MCPcopy
hub / github.com/aceld/zinx / main

Function main

examples/zinx_RequestPollMode/client/client.go:62–86  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

60}
61
62func 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}

Callers

nothing calls this directly

Calls 6

SetOnConnStartMethod · 0.95
SetOnConnStopMethod · 0.95
AddRouterMethod · 0.95
StartMethod · 0.95
StopMethod · 0.95
NewClientFunction · 0.92

Tested by

no test coverage detected