1. 程式人生 > >開源Golang遊戲伺服器框架cellnet

開源Golang遊戲伺服器框架cellnet

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()
}