|
|
@@ -172,6 +172,14 @@ int main() {
|
|
|
}
|
|
|
```
|
|
|
|
|
|
+**注意**:
|
|
|
+
|
|
|
+以上示例只是简单的`echo`服务,TCP是流式协议,实际应用中请务必添加边界进行拆包。<br>
|
|
|
+文本协议建议加上`\0`或者`\r\n`分隔符,可参考 [examples/jsonrpc](examples/jsonrpc);<br>
|
|
|
+二进制协议建议加上自定义协议头,通过头部长度字段表明负载长度,可参考 [examples/protorpc](examples/protorpc);<br>
|
|
|
+然后通过`hio_set_unpack`、`TcpServer::setUnpack`设置拆包规则。<br>
|
|
|
+不想自定义协议和拆包组包的可直接使用现成的`HTTP/WebSocket`协议。<br>
|
|
|
+
|
|
|
#### TCP客户端
|
|
|
**c版本**: [examples/nc.c](examples/nc.c)
|
|
|
```c
|
|
|
@@ -479,6 +487,7 @@ ab -c 100 -n 100000 http://127.0.0.1:8080/
|
|
|
- [libhv教程15--200行实现一个C++版protorpc框架](https://hewei.blog.csdn.net/article/details/119966701)
|
|
|
- [libhv教程16--多线程/多进程服务端编程](https://hewei.blog.csdn.net/article/details/120366024)
|
|
|
- [libhv教程17--Qt中使用libhv](https://hewei.blog.csdn.net/article/details/120699890)
|
|
|
+- [libhv教程18--动手写一个tinyhttpd](https://hewei.blog.csdn.net/article/details/121706604)
|
|
|
|
|
|
## 💎 用户案例
|
|
|
|