DoClientConnectedBegin is the callback function when connection starts DoClientConnectedBegin 是连接开始时的回调函数
(conn ziface.IConnection)
| 32 | // DoClientConnectedBegin is the callback function when connection starts |
| 33 | // DoClientConnectedBegin 是连接开始时的回调函数 |
| 34 | func 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 是连接断开时的回调函数 |
nothing calls this directly
no test coverage detected