go高性能服务器框架

network.StartTcpServer(":8088", network.OptionHandler(func(conn net.Conn) (err error) {
        Stage().ActorOf(WithRemoteStream(func(ctx ActorContext) {
            switch body := ctx.Any().(type) {
            case *Started:
                fmt.Println("connect addr:", conn.RemoteAddr().String())
            case *Stopped:
            case []byte:
                fmt.Println("message: ", network.ReadBegin(body))
                ctx.Send(ctx.Self(), network.WriteBegin(0x102).Flush())
            case error: //设置了心跳会被通知
            default:
                fmt.Printf("untreated type %T \n", body)
            }
        }, conn))
        return
    }))

cli := Stage().ActorOf(WithRemoteAddr(func(ctx ActorContext) {
	switch body := ctx.Any().(type) {
	case *Started:
		fmt.Println("open ok")
	case *Stopped:
	case []byte:
		fmt.Println("cli respond: ", network.ReadBegin(body))
	case Failure: //最终错误退出的原因

	default:
		fmt.Printf("other object miss handle %T \n", body)
	}
}, "localhost:8088"))

psend := network.WriteBegin(0x101, "who's your daddy!")
cli.Tell(psend.Flush())

git地址:https://github.com/okpub/rhino

欢迎服务器开发者和爱好者入群交流,腾讯,百度,阿里技术大牛在线分享

共 1 个回复


roar090

关注,支持一下

# 0