Example #1
0
// 收到客户端消息
func OnDataReceive(session *tcpsession.Tcpsession, rpk *packet.Rpacket) {
	key := session.GetKey().(*Key)
	// 注册
	if key.nFlag == FLAG_NON {
		msg, _ := rpk.String()
		gameid, _ := rpk.String()
		key.gameid = gameid
		// server
		if msg == "server" {
			key.nFlag = FLAG_SVR
			GameidToSession[gameid] = session
			fmt.Println("server RegisterOk   ", gameid)
		} else {
			// client
			key.nFlag = FLAG_CLT
			fmt.Println("client RegisterOk  To ", gameid)
		}
		wpk := packet.NewWpacket(packet.NewByteBuffer(64), false)
		wpk.PutString("registerOk")
		session.Send(wpk, OnSendFinish)
		return
	}

	if key.nFlag == FLAG_CLT {
		SendToServer(key, session, rpk)
		return
	}

	if key.nFlag == FLAG_SVR {
		SendToClient(key, session, rpk)
	}

}
Example #2
0
// 收到客户端消息
func OnDataReceive(session *tcpsession.Tcpsession, rpk *packet.Rpacket) {
	//session.Send(packet.NewWpacket(rpk.Buffer(), rpk.IsRaw()), OnSendFinish)
	uuid, _ := rpk.String()
	msg, _ := rpk.String()
	fmt.Println("收到uuid:", uuid, "转发过来的消息:", msg)
	echo := packet.NewWpacket(packet.NewByteBuffer(1024), false)
	echo.PutString(uuid)
	echo.PutString(msg)
	session.Send(echo, OnSendFinish)
}