发送数据 - TcpClientSend
函数简介
发送数据(异步操作)。
接口名称
TcpClientSend
DLL调用
int32_t TcpClientSend(int64_t instance, int64_t client_handle, int64_t data, int32_t data_len);
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| client_handle | 长整数型 | 客户端句柄 |
| data | 长整数型 | 数据指针 |
| data_len | 整数型 | 数据长度 |
示例
// 发送字符串
const char* message = "Hello Server";
int32_t result = TcpClientSend(instance, client, (int64_t)message, strlen(message));
if (result == 1) {
printf("数据已加入发送队列\n");
}
返回值
整数型,1 成功(加入发送队列),0 失败。
注意事项
- 这是异步操作,数据会被加入发送队列
- 发送完成后会触发回调(event_type=4)
- 如果启用了分包协议,会自动添加4字节长度前缀
- 如果未连接,发送会失败
- 数据会被复制,调用后可以立即释放原始数据
