本文整理汇总了Golang中github.com/davyxu/cellnet.BuildPacket函数的典型用法代码示例。如果您正苦于以下问题:Golang BuildPacket函数的具体用法?Golang BuildPacket怎么用?Golang BuildPacket使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BuildPacket函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: server
func server() {
ltvsocket.SpawnAcceptor("127.0.0.1:8001", func(self cellnet.CellID, cm interface{}) {
switch v := cm.(type) {
case ltvsocket.EventAccepted:
ltvsocket.SpawnSession(v.Stream(), func(ses cellnet.CellID, sescm interface{}) {
switch pkt := sescm.(type) {
case *cellnet.Packet:
log.Println("server recv:", cellnet.ReflectContent(pkt))
v.Stream().Write(cellnet.BuildPacket(&coredef.TestEchoACK{
Content: proto.String("world"),
}))
}
})
case IError:
log.Println(cellnet.ReflectContent(v))
}
})
}
示例2: Call
func Call(p cellnet.Peer, args interface{}, callback interface{}) {
req := addCall()
funcType := reflect.TypeOf(callback)
req.replyType = funcType.In(0).Elem()
req.callback = reflect.ValueOf(callback)
ses, err := getPeerSession(p)
if err != nil {
log.Errorln(err)
removeCall(req.id)
return
}
pkt, _ := cellnet.BuildPacket(args)
ses.Send(&coredef.RemoteCallREQ{
MsgID: proto.Uint32(pkt.MsgID),
Data: pkt.Data,
CallID: proto.Int64(req.id),
})
// TODO rpc日志
}
示例3: Send
func (self *ltvSession) Send(data interface{}) {
pkt, _ := cellnet.BuildPacket(data)
msgLog("send", self, pkt)
self.RawSend(pkt)
}
示例4: Send
func (self *ltvSession) Send(data interface{}) {
pkt, meta := cellnet.BuildPacket(data)
log.Debugf("#send(%s) sid: %d %s(%d)|%s", self.FromPeer().Name(), self.ID(), meta.Name, len(pkt.Data), data.(proto.Message).String())
self.RawSend(pkt)
}
示例5: Feedback
func (self *response) Feedback(msg interface{}) {
pkt, _ := cellnet.BuildPacket(msg)
self.ses.Send(&gamedef.RemoteCallACK{
MsgID: pkt.MsgID,
Data: pkt.Data,
CallID: self.req.CallID,
})
}
示例6: Feedback
func (self *response) Feedback(msg interface{}) {
pkt, _ := cellnet.BuildPacket(msg)
self.ses.Send(&coredef.RemoteCallACK{
MsgID: proto.Uint32(pkt.MsgID),
Data: pkt.Data,
CallID: proto.Int64(self.req.GetCallID()),
})
}
示例7: SendToClient
// 将消息发送到客户端
func SendToClient(gateSes cellnet.Session, clientid int64, data interface{}) {
if gateSes == nil {
return
}
userpkt := cellnet.BuildPacket(data)
gateSes.Send(&coredef.DownstreamACK{
Data: userpkt.Data,
MsgID: proto.Uint32(userpkt.MsgID),
ClientID: []int64{clientid},
})
}
示例8: sendMessageToBackend
func sendMessageToBackend(ses cellnet.Session, ev *socket.SessionEvent) {
// 构建路由封包
relaypkt, _ := cellnet.BuildPacket(&coredef.UpstreamACK{
MsgID: ev.MsgID,
Data: ev.Data,
ClientID: ev.Ses.ID(),
})
if DebugMode {
log.Debugf("client->backend, msg: %s(%d) clientid: %d", getMsgName(ev.MsgID), ev.MsgID, ev.Ses.ID())
}
ses.RawSend(relaypkt)
}
示例9: BroadcastToClientList
// 发送给指定客户端列表的客户端
func BroadcastToClientList(data interface{}, list ClientList) {
pkt := cellnet.BuildPacket(data)
for ses, clientlist := range list {
ack := &coredef.DownstreamACK{
Data: pkt.Data,
MsgID: proto.Uint32(pkt.MsgID),
}
ack.ClientID = clientlist
ses.Send(ack)
}
}
示例10: StartClientAcceptor
// 开启客户端侦听通道
func StartClientAcceptor(pipe cellnet.EventPipe, address string) {
ClientAcceptor = socket.NewAcceptor(pipe)
// 所有接收到的消息转发到后台
ClientAcceptor.InjectData(func(data interface{}) bool {
if ev, ok := data.(*socket.SessionEvent); ok {
// Socket各种事件不要往后台发
switch ev.MsgID {
case socket.Event_SessionAccepted,
socket.Event_SessionConnected:
return true
}
// 构建路由封包
relaypkt := cellnet.BuildPacket(&coredef.UpstreamACK{
MsgID: proto.Uint32(ev.MsgID),
Data: ev.Data,
ClientID: proto.Int64(ev.Ses.ID()),
})
// TODO 按照封包和逻辑固定分发
// TODO 非法消息直接掐线
// TODO 心跳, 超时掐线
BackendAcceptor.IterateSession(func(ses cellnet.Session) bool {
if DebugMode {
log.Printf("client->backend, msgid: %d clientid: %d data: %v", ev.MsgID, ev.Ses.ID(), ev.Data)
}
ses.RawSend(relaypkt)
return true
})
}
return false
})
ClientAcceptor.Start(address)
}
示例11: BroadcastToClient
// 发送给所有gate的所有客户端
func BroadcastToClient(data interface{}) {
pkt := cellnet.BuildPacket(data)
ack := &coredef.DownstreamACK{
Data: pkt.Data,
MsgID: proto.Uint32(pkt.MsgID),
}
for _, conn := range gateConnArray {
ses := conn.(connSesManager).DefaultSession()
if ses == nil {
continue
}
ses.Send(ack)
}
}
示例12: Send
func (self *ltvSession) Send(data interface{}) {
pkt, meta := cellnet.BuildPacket(data)
if EnableMessageLog {
msgLog(&MessageLogInfo{
Dir: "send",
PeerName: self.FromPeer().Name(),
SessionID: self.ID(),
Name: meta.Name,
ID: meta.ID,
Size: int32(len(pkt.Data)),
Data: data.(proto.Message).String(),
})
}
self.RawSend(pkt)
}
示例13: SendToClient
// 将消息发送到客户端
func SendToClient(routerSes cellnet.Session, clientid int64, data interface{}) {
if routerSes == nil {
return
}
msgContent := data.(interface {
String() string
}).String()
userpkt, _ := cellnet.BuildPacket(data)
log.Debugf("backend->router clientid: %d %s(%d) size: %d |%s", clientid, getMsgName(userpkt.MsgID), userpkt.MsgID, len(userpkt.Data), msgContent)
routerSes.Send(&coredef.DownstreamACK{
Data: userpkt.Data,
MsgID: userpkt.MsgID,
ClientID: []int64{clientid},
})
}
示例14: client
func client() {
ltvsocket.SpawnConnector("127.0.0.1:8001", func(self cellnet.CellID, cm interface{}) {
switch v := cm.(type) {
case ltvsocket.EventConnected:
// new session
ltvsocket.SpawnSession(v.Stream(), func(ses cellnet.CellID, sescm interface{}) {
switch pkt := sescm.(type) {
case *cellnet.Packet:
var ack coredef.TestEchoACK
if err := proto.Unmarshal(pkt.Data, &ack); err != nil {
log.Println(err)
} else {
log.Println("client recv", ack.String())
done <- true
}
}
})
// send packet on connected
v.Stream().Write(cellnet.BuildPacket(&coredef.TestEchoACK{
Content: proto.String("hello"),
}))
case IError:
log.Println(cellnet.ReflectContent(v))
}
})
}
示例15: BroadcastToClientList
// 发送给指定客户端列表的客户端
func BroadcastToClientList(data interface{}, list ClientList) {
msgContent := data.(interface {
String() string
}).String()
pkt, _ := cellnet.BuildPacket(data)
log.Debugf("backend->router BroadcastToClientList %s(%d) size: %d|%s", getMsgName(pkt.MsgID), pkt.MsgID, len(pkt.Data), msgContent)
for ses, clientlist := range list {
ack := &coredef.DownstreamACK{
Data: pkt.Data,
MsgID: pkt.MsgID,
}
ack.ClientID = clientlist
ses.Send(ack)
}
}