断开指定连接 - TcpServerDisconnect
函数简介
断开指定的客户端连接。
接口名称
TcpServerDisconnect
DLL调用
int32_t TcpServerDisconnect(int64_t instance, int64_t server_handle, int64_t conn_id);
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| server_handle | 长整数型 | 服务端句柄 |
| conn_id | 长整数型 | 连接ID |
示例
// 在回调中断开连接
void OnTcpServerEvent(int64_t server_handle, int64_t conn_id, int32_t event_type,
int64_t data, int32_t data_len, int64_t user_data) {
if (event_type == 1) { // 收到数据
const char* msg = (char*)data;
// 如果收到"quit",断开该客户端
if (strncmp(msg, "quit", 4) == 0) {
TcpServerDisconnect(instance, server_handle, conn_id);
}
}
}
返回值
整数型,1 成功,0 失败。
注意事项
- 断开后会触发回调(event_type=2)
- 如果连接不存在,调用会失败
- 断开是异步操作,可能不会立即完成
- 断开后,conn_id失效
