skywind3000/kcp
Free:zap: KCP - A Fast and Reliable ARQ Protocol
About skywind3000/kcp
KCP is a fast and reliable ARQ (Automatic Repeat-reQuest) protocol implemented in pure C. It is designed to reduce average latency by 30-40% and maximum latency by three times compared to TCP, at the cost of 10-20% additional bandwidth usage. KCP is a pure algorithm implementation that does not handle underlying protocol transmission (e.g., UDP); it requires the user to define how to send packets via callbacks. The protocol consists of only two source files (ikcp.h and ikcp.c), making it easy to integrate into existing projects. KCP employs several techniques to improve transmission speed: non-exponential RTO backoff (1.5x instead of 2x), selective retransmission, fast retransmit (triggers after two duplicate ACKs), non-delayed ACK, and combined UNA+ACK in every packet. It also provides configurable congestion control, with a normal mode similar to TCP and a fast mode that sacrifices some fairness for lower latency. KCP is widely used in real-time applications such as online gaming, live streaming, and other scenarios where low latency over unreliable transport is critical.
Key Features
Pros & Cons
- Significantly lower latency (30-40% average, up to 3x max) compared to TCP
- Open-source and permissively licensed (MIT-like)
- Very easy to integrate: two source files, no external dependencies
- Highly configurable to balance between speed and bandwidth usage
- Pure algorithm – no OS-specific calls, portable to any platform
- Uses 10-20% more bandwidth than TCP for the same throughput
- Not a full transport protocol; requires underlying unreliable transport (e.g., UDP) and manual packet I/O
- No built-in MTU discovery; MTU must be set manually
- Does not handle session management, encryption, or congestion control in the same comprehensive way as TCP
- Not designed for bulk data transfer where bandwidth efficiency is paramount