DoConnectionBegin is the callback function when connection starts DoConnectionBegin 是连接开始时的回调函数
(conn ziface.IConnection)
| 12 | // DoConnectionBegin is the callback function when connection starts |
| 13 | // DoConnectionBegin 是连接开始时的回调函数 |
| 14 | func DoConnectionBegin(conn ziface.IConnection) { |
| 15 | fmt.Println("Server connection started") |
| 16 | |
| 17 | // Set connection properties / 设置连接属性 |
| 18 | conn.SetProperty("StartTime", time.Now()) |
| 19 | |
| 20 | // Add close callback function - cleanup resources / 添加关闭回调函数 - 清理资源 |
| 21 | conn.AddCloseCallback("cleanup", "resources", func() { |
| 22 | fmt.Printf("Cleanup resources for connection %d\n", conn.GetConnID()) |
| 23 | }) |
| 24 | |
| 25 | // Add close callback function - record statistics / 添加关闭回调函数 - 记录统计信息 |
| 26 | conn.AddCloseCallback("stats", "record", func() { |
| 27 | if startTime, err := conn.GetProperty("StartTime"); err == nil { |
| 28 | duration := time.Since(startTime.(time.Time)) |
| 29 | fmt.Printf("Connection %d duration: %v\n", conn.GetConnID(), duration) |
| 30 | } |
| 31 | }) |
| 32 | |
| 33 | // Add close callback function - notify other components / 添加关闭回调函数 - 通知其他组件 |
| 34 | conn.AddCloseCallback("notification", "broadcast", func() { |
| 35 | fmt.Printf("Notify other components: connection %d disconnected\n", conn.GetConnID()) |
| 36 | }) |
| 37 | } |
| 38 | |
| 39 | // DoConnectionLost is the callback function when connection is lost |
| 40 | // DoConnectionLost 是连接断开时的回调函数 |
nothing calls this directly
no test coverage detected