KCP是一个快速可靠协议,能以比 TCP浪费10%-20%的带宽的代价,换取平均延迟降低 30%-40%,且最大延迟降低三倍的传输效果。纯算法实现,并不负责底层协议(如UDP)的收发,需要使用者自己定义下层数据包的发送方式,以 callback的方式提供给 KCP。 连时钟都需要外部传递进来,内部不会有任何一次系统调用。
整个协议只有 ikcp.h, ikcp.c两个源文件,可以方便的集成到用户自己的协议栈中。也许你实现了一个P2P,或者某个基于 UDP的协议,而缺乏一套完善的ARQ可靠协议实现,那么简单的拷贝这两个文件到现有项目中,稍微编写两行代码,即可使用。
**
Features(特性)
**
*
100% compatible with original C version.(100%兼容ikcp.c)
*
Pure golang implementation of KCP in a single file [kcp.go](https://github.com/xtaci/kcp-go/blob/master/kcp.go).(纯golang实现)
*
Instead of container.List, kcp-go made use of slice based internal queue. (slice优化的传输队列)
*
Provides a basic [session manager](https://github.com/xtaci/kcp-go/blob/master/sess.go), compatible with [net.Conn](https://golang.org/pkg/net/#Conn) and [net.Listener](https://golang.org/pkg/net/#Listener).(接口兼容net.Conn/net.Listener)
*
Seperated KCP code and session manager code, you can use kcp.go only without session manager.(独立的会话管理)
* Conventions(实现约定)
*
conv uint32 in session manager is a random number initiated by client. (conv由客户端产生随机数)
*
conn.Write never blocks in KCP, so conn.SetWriteDeadline has no use.(写无阻塞)
*
KCP doesn't define control messages like SYN/FIN/RST in TCP, a real world example is to use TCP & KCP at the same time, of which TCP does session control(eg. UDP disconnecting.), and UDP does message delivery. (需要结合TCP实现链路控制)
****
**
**