()
| 60 | } |
| 61 | |
| 62 | func main() { |
| 63 | // Create a client handle using Zinx's Method (创建一个Client句柄,使用Zinx的方法) |
| 64 | client := znet.NewClient("127.0.0.1", 8999) |
| 65 | |
| 66 | // Set the business logic to execute when the connection is created or lost |
| 67 | // (添加首次建立连接时的业务) |
| 68 | client.SetOnConnStart(DoClientConnectedBegin) |
| 69 | client.SetOnConnStop(DoClientConnectedLost) |
| 70 | |
| 71 | // Register routers for the messages received from the server |
| 72 | // (注册收到服务器消息业务路由) |
| 73 | client.AddRouter(2, &c_router.PingRouter{}) |
| 74 | client.AddRouter(3, &c_router.HelloRouter{}) |
| 75 | |
| 76 | // Start the client |
| 77 | client.Start() |
| 78 | |
| 79 | // close |
| 80 | c := make(chan os.Signal, 1) |
| 81 | signal.Notify(c, os.Interrupt, os.Kill) |
| 82 | sig := <-c |
| 83 | fmt.Println("===exit===", sig) |
| 84 | client.Stop() |
| 85 | time.Sleep(time.Second * 2) |
| 86 | } |
nothing calls this directly
no test coverage detected