-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
game模块:
skeleton.RegisterChanRPC("EventNameAbc", rpcEventFunc)// 在game模块的init()函数中注册
//这个是上面监听的回调函数, 注意:这个是直接调用没有返回的
func rpcEventFunc(args interface{}) {
byteData, _ := json.Marshal(args)
log.Debug(string(byteData))
}
//这个是上面监听的回调函数, 注意:这个是返回1个参数的
func rpcEventFunc(args interface{}) interface{} {
byteData, _ := json.Marshal(args)
log.Debug(string(byteData))
return 1
}
//这个是上面监听的回调函数, 注意:这个是返回2个以上参数的
func rpcEventFunc(args interface{}) interface{} {
byteData, _ := json.Marshal(args)
log.Debug(string(byteData))
return []interface{}{1, 2}
}
//---------------------下面是向game模块发送上面的事件-------------------------------
//在任意除game模块中使用game.ChanRPC.Call1来发送数据
type Req struct {
ParamA int32 json:"param_a"
}
//针对不返回的发送1个参数的
game.ChanRPC.Go("EventNameAbc", &Req{ParamA: 1})
//针对不返回的发送2个参数的
game.ChanRPC.Go("EventNameAbc", &Req{ParamA: 1}, &Req{ParamA: 1})
//针对返回1个以上的数据的
resp, err := game.ChanRPC.Call1("EventNameAbc", &Req{ParamA: 1})
if err!=nil {
log.Debug("返回错误",err)
}
log.Debug("返回的数据是int %s",resp) //如果是返回多个,则resp是 [ ]interface{}
说明, 这个Call有Call0, Call1, CallN 用法一样, 针对其他模块注册的监听函数的返回值进行使用