本文整理匯總了Golang中github.com/funny/link.Session.Receive方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.Receive方法的具體用法?Golang Session.Receive怎麽用?Golang Session.Receive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/funny/link.Session
的用法示例。
在下文中一共展示了Session.Receive方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: newFrontLink
func newFrontLink(session *link.Session, linkID uint64) *frontendLink {
flink := &frontendLink{
session: session,
linkId: linkID,
clients: make(map[uint64]*link.Session),
clientWaits: make(map[uint64]*link.Session),
}
session.AddCloseCallback(flink, func() {
flink.Close()
})
go func() {
var msg = gatewayMsg{}
for {
if err := session.Receive(&msg); err != nil {
break
}
switch msg.Command {
case CMD_MSG:
flink.dispathMsg(msg.ClientId, msg.Data)
case CMD_BRD:
flink.broadcast(msg.ClientIds, msg.Data)
case CMD_NEW_2:
flink.newClient(msg.ClientId, msg.ClientIds[0])
case CMD_DEL:
flink.delClient(msg.ClientId, false)
}
}
flink.Close()
}()
return flink
}
示例2: sessionReceive
func sessionReceive(session *link.Session, d dispatch.DispatchInterface) {
for {
var msg []byte
if err := session.Receive(&msg); err != nil {
break
}
d.Process(session, msg)
}
}
示例3: BytesTest
func BytesTest(t *testing.T, session *link.Session) {
for i := 0; i < 2000; i++ {
msg1 := RandBytes(512)
err := session.Send(msg1)
unitest.NotError(t, err)
var msg2 []byte
err = session.Receive(&msg2)
unitest.NotError(t, err)
unitest.Pass(t, bytes.Equal(msg1, msg2))
}
}
示例4: ObjectTest
func ObjectTest(t *testing.T, session *link.Session) {
for i := 0; i < 2000; i++ {
msg1 := RandObject()
err := session.Send(&msg1)
unitest.NotError(t, err)
var msg2 TestObject
err = session.Receive(&msg2)
unitest.NotError(t, err)
unitest.Pass(t, msg1 == msg2)
}
}
示例5: StringTest
func StringTest(t *testing.T, session *link.Session) {
for i := 0; i < 2000; i++ {
msg1 := string(RandBytes(512))
err := session.Send(msg1)
unitest.NotError(t, err)
var msg2 string
err = session.Receive(&msg2)
unitest.NotError(t, err)
unitest.Pass(t, msg1 == msg2)
}
}
示例6: startDealReceiveMsgC2S
//開始處理遊戲邏輯消息
func startDealReceiveMsgC2S(session *link.Session) {
revMsgChan := make(chan *packet.RAW, 2048)
go func() {
for {
data, ok := <-revMsgChan
if !ok {
return
}
dealReceiveMsgC2S(session, *data)
}
}()
for {
var msg packet.RAW
if err := session.Receive(&msg); err != nil {
break
}
revMsgChan <- &msg
}
}