elisaday / kcpuv Goto Github PK
View Code? Open in Web Editor NEW使用KCP和libuv的简单网络模块。
License: GNU General Public License v2.0
使用KCP和libuv的简单网络模块。
License: GNU General Public License v2.0
看到alive()的调用在conn.cpp:176行,Conn::run()里调用的。
这个只有在收到数据的时候才会被触发。
如果是只发送数据,不接收数据,就会超时出错。
我一直在用libuv做开发
本来很想尝试改下然后嵌入到我们的项目。但是发现框架影响太大了。
不知道是不是我没太理解清楚还是别的原因
个人感觉应该实现应该只提供好连接管理就行了,不要在上面再做一层libuv的封装。
如果再做一层libuv的封装,把uv_run都隐藏了,这样对其他已有libuv的项目来说结构影响太大?
个人觉得理想的方式是:
服务器:
uv_loop *loop;
kcpuv_server_init(loop, kcp_server);
kcpuv_bind(kcp_server , addr);
kcpuv_listen(kcp_server);
kcpuv_server_start(kcp_server , on_peer_connect_handle);
void on_peer_connect_handle(kcp_server) {
kcp_client *peer = kcpuv_peer_init(loop);
kcpuv_accept(kcp_server, peer);
kcpuv_start_read(peer, on_data_handle);
}
客户端:
kcpuv_client_init(loop, kcp_client);
kcpuv_connect(kcp_client, addr);
kcpuv_client_start(kcp_server , on_client_connect_handle);
void on_client_connect_handle(kcp_client) {
kcpuv_start_read(kcp_client, on_read_handle);
}
另外,libuv本身是C89,我觉得如果是要做这种封装,最好也是用C89
cmake之後,用VS2015打開,重新生成,產生一大堆無法解析的外部命令
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.