智慧 + 毅力 = 无所不能

正确性、健壮性、可靠性、效率、易用性、可读性、可复用性、兼容性、可移植性...

导航

KCP 传输协议

Posted on 2017-07-07 17:44  Bill Yuan  阅读(1849)  评论(0编辑  收藏  举报

 

作者:韦易笑
链接:https://www.zhihu.com/question/36258781/answer/98944369
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

KCP 传输协议:GitHub - skywind3000/kcp: KCP

libenet的协议设计是非常落后的,基本上就是90年代教科书上那种标准ARQ协议实现,很难在复杂的网络条件下提供可靠的低延迟传输效果。而KCP具备更多现代传输协议的特点,诸如:
流量换延迟,快速重传,流控优化,una/ack优化等。

在内网这种几乎理想的环境里直接比较,大家都差不多,但是放到公网上,放到3G/4G网络情况下,或者使用内网丢包模拟,差距就很明显了。公网在高峰期有平均接近10%的丢包,wifi/3g/4g下更糟糕,这些都会让传输变卡。


asio-kcp 的作者对 KCP 与 enet, udt 做过的一次横向评测,结论是KCP比 libenet,udt更适合实时PVP游戏,特别是使用手机的3G,4G网络的情况下:


  • ASIO-KCP has good performace in wifi and phone network(3G, 4G).
  • The kcp is the first choice for realtime pvp game.
  • The lag is less than 1 second when network lag happen. 3 times better than enet when lag happen.
  • The enet is a good choice if your game allow 2 second lag.
  • UDT is a bad idea. It always sink into badly situation of more than serval seconds lag. And the recovery is not expected.
  • enet has the problem of lack of doc. And it has lots of functions that you may intrest.
  • kcp's doc is chinese. Good thing is the function detail which is writen in code is english. And you can use asio_kcp which is a good wrap.
  • The kcp is a simple thing. You will write more code if you want more feature.
  • UDT has a perfect doc. UDT may has more bug than others as I feeling.

基于kcp的开源项目也不少,比如:
  • kcptun: 基于 kcp-go做的高速远程端口转发(隧道) ,配合ssh -D,可以比 shadowsocks 更流畅的看 youtube视频。
  • kcp-go: 高安全性的kcp的 GO语言实现,包含 UDP会话管理的简单实现,可以作为后续开发的基础库。
  • asio-kcp: 使用 KCP的完整 UDP网络库,完整实现了基于 UDP的链接状态管理,会话控制,KCP协议调度等
  • v2ray: Shadowsocks 代替者,1.17后集成了 kcp协议,使用UDP传输,无数据包特征。
  • dog-tunnel: GO开发的网络隧道,使用 KCP极大的改进了传输速度

不管是何种同步算法,都需要更先进的网络传输技术,而使用libenet这种20年前的老技术,没法很好的解决这一问题,我们需要更加先进现代的传输协议,来达到这个目标。

----
本专业学通信的,闲着没事喜欢折腾各种传输协议。

更多阅读:
reliable_udp_bench_mark: Test reliable udp for situation of realtime pvp game by wireless.
通过KCP协议加速科学上网
--

另,具体同步算法我回答过无数遍了,不再复述:

手机格斗网游该如何避免延迟? - 韦易笑的回答

FPS游戏中,在玩家的延时都不一样的情况下是如何做到游戏的同步性的? - 韦易笑的回答

Skywind Inside - 网游同步法则