package main import ( "fmt" "github.com/valyala/gorpc" "time" ) var server_summary *ServerSummary var storage *Storage var appid int64 = 0 var device_id int64 = 0 var master *Master var config *StorageConfig func main() { d := gorpc.NewDispatcher() d.AddFunc("SyncMessage", SyncMessage) d.AddFunc("SyncGroupMessage", SyncGroupMessage) d.AddFunc("SavePeerMessage", SavePeerMessage) c := gorpc.NewTCPClient("127.0.0.1:13333") //ims地址 c.Start() defer c.Stop() dc := d.NewFuncClient(c) //-----------------测试核心代码/----------------- /* 功能说明:模拟对IMS进行RPC调用,方法SavePeerMessage 主要用作IMS端的调试 需要注意:IMMessage,Message,PeerMessage三者的区别 */ im := &IMMessage{sender: 1, receiver: 1000, timestamp: int32(time.Now().Unix()), msgid: 5, content: "hello"} m := &Message{cmd: MSG_IM, seq: 5, version: 2, flag: 0, body: im} r, err := dc.Call("SavePeerMessage", &PeerMessage{ 0, 1000, 0, 4, m.ToData(), }) if err != nil { fmt.Println("调用错误") } else { fmt.Println(r) } }