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

Function DoClientConnectedBegin

examples/zinx_closecallback/client/client.go:34–50  ·  view source on GitHub ↗

DoClientConnectedBegin is the callback function when connection starts DoClientConnectedBegin 是连接开始时的回调函数

(conn ziface.IConnection)

Source from the content-addressed store, hash-verified

32// DoClientConnectedBegin is the callback function when connection starts
33// DoClientConnectedBegin 是连接开始时的回调函数
34func DoClientConnectedBegin(conn ziface.IConnection) {
35 fmt.Println("Client connection started")
36
37 // Set connection properties / 设置连接属性
38 conn.SetProperty("StartTime", time.Now())
39
40 // Add close callback function - record connection statistics / 添加关闭回调函数 - 记录连接统计
41 conn.AddCloseCallback("stats", "connection-stats", func() {
42 if startTime, err := conn.GetProperty("StartTime"); err == nil {
43 duration := time.Since(startTime.(time.Time))
44 fmt.Printf("Client connection duration: %v\n", duration)
45 }
46 })
47
48 // Start business processing / 启动业务处理
49 go business(conn)
50}
51
52// DoClientConnectedLost is the callback function when connection is lost
53// DoClientConnectedLost 是连接断开时的回调函数

Callers

nothing calls this directly

Calls 4

businessFunction · 0.70
SetPropertyMethod · 0.65
AddCloseCallbackMethod · 0.65
GetPropertyMethod · 0.65

Tested by

no test coverage detected