當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Session.Receive方法代碼示例

本文整理匯總了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
}
開發者ID:youxidev,項目名稱:GoGameServer,代碼行數:34,代碼來源:frontend_link.go

示例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)
	}
}
開發者ID:yicaoyimuys,項目名稱:GoGameServer,代碼行數:10,代碼來源:startup.go

示例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))
	}
}
開發者ID:sanbit,項目名稱:link,代碼行數:12,代碼來源:all_test.go

示例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)
	}
}
開發者ID:sanbit,項目名稱:link,代碼行數:12,代碼來源:all_test.go

示例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)
	}
}
開發者ID:sanbit,項目名稱:link,代碼行數:12,代碼來源:all_test.go

示例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
	}
}
開發者ID:youxidev,項目名稱:GoGameServer,代碼行數:21,代碼來源:transferProxyServer.go


注:本文中的github.com/funny/link.Session.Receive方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。