コード例 #1
0
//初始化
func InitServer(port string) error {
	servers = make(map[string][]Server)
	gameConsistent = hashs.NewConsistent()
	gameUserSessions = make(map[uint64]int)

	//监听tcp
	addr := "0.0.0.0:" + port
	err := global.Listener("tcp", addr, global.PackCodecType_Safe,
		func(session *link.Session) {},
		serverMsgDispatch,
	)

	return err
}
コード例 #2
0
//初始化
func InitServer(port string) error {
	servers = make(map[string][]*link.Session)
	gameConsistent = hashs.NewConsistent()
	gameUserSessions = make(map[uint64]int)

	listener, err := link.Serve("tcp", "0.0.0.0:"+port, packet.New(
		binary.SplitByUint32BE, 1024, 1024, 1024,
	))
	if err != nil {
		return err
	}

	listener.Serve(func(session *link.Session) {
		var msg packet.RAW
		for {
			if err := session.Receive(&msg); err != nil {
				break
			}
			dealReceiveMsgC2S(session, msg)
		}
	})

	return nil
}