β

开源Golang游戏服务器框架cellnet

C++博客-首页原创精华区 708 阅读

简单,方便,高效的Go语言的游戏服务器框架

func server() {
 
    pipe := cellnet.NewEventPipe()
 
    evq := socket.NewAcceptor(pipe).Start("127.0.0.1:7234")
 
    socket.RegisterSessionMessage(evq, coredef.TestEchoACK{}, func(content interface{}, ses cellnet.Session) {
        msg := content.(*coredef.TestEchoACK)
 
        log.Println("server recv:", msg.String())
 
        ses.Send(&coredef.TestEchoACK{
            Content: proto.String(msg.String()),
        })
 
    })
 
    pipe.Start()
 
}
 
func client() {
 
    pipe := cellnet.NewEventPipe()
 
    evq := socket.NewConnector(pipe).Start("127.0.0.1:7234")
 
    socket.RegisterSessionMessage(evq, coredef.TestEchoACK{}, func(content interface{}, ses cellnet.Session) {
        msg := content.(*coredef.TestEchoACK)
 
        log.Println("client recv:", msg.String())
 
    })
 
    socket.RegisterSessionMessage(evq, coredef.SessionConnected{}, func(content interface{}, ses cellnet.Session) {
 
        ses.Send(&coredef.TestEchoACK{
            Content: proto.String("hello"),
        })
 
    })
 
    pipe.Start()
}

项目地址: https://github.com/davyxu/cellnet



战魂小筑 2015-10-16 11:44 发表评论
作者:C++博客-首页原创精华区
专注于C++技术
原文地址:开源Golang游戏服务器框架cellnet, 感谢原作者分享。

发表评论