kcp
:zap: KCP - A Fast and Reliable ARQ Protocol
A tiny C library that implements a fast reliable UDP protocol, cutting network latency by 30-40% compared to TCP at the cost of a small amount of extra bandwidth, ideal for games, video calls, and real-time apps.
KCP is a network protocol for sending data between two computers over the internet, written as a small library in C. The README's selling point is the trade-off it makes against TCP, the standard protocol the web and most apps use. KCP gives up roughly ten to twenty percent more bandwidth, and in exchange the data arrives noticeably faster — the README quotes an average latency reduction of thirty to forty percent and a worst-case latency that can be three times lower. It compares TCP to a slow but high-volume canal and KCP to a small but fast-moving stream.
KCP is an ARQ protocol, meaning it numbers the packets it sends and asks the other side to acknowledge each one, retransmitting anything that goes missing. To get its speed it uses several tricks: when a packet is lost, only the missing one is resent rather than everything after it; the retransmission timeout grows by a factor of 1.5 rather than 2 so a few lost packets do not balloon delays; acknowledgement packets carry both per-packet and cumulative information; and a fast-resend mode re-sends a packet as soon as later ones have been acknowledged.
KCP itself is just a pure algorithm shipped as two files, ikcp.h and ikcp.c. It does not open sockets. The application has to provide a callback that pushes bytes onto something like UDP, feed incoming packets back into the library, and call an update function on a regular tick. You'd reach for KCP in interactive games, voice or video calls, P2P tools or remote control where low latency matters more than raw throughput. The README also lists many community ports to Go, Java, C#, Rust, Lua, Node and Python. The full README is longer than what was provided.
Where it fits
- Build a multiplayer game where players need sub-100ms round trips and TCP latency is too high.
- Implement a low-latency voice or video call system that recovers faster from dropped packets than TCP.
- Create a P2P remote-desktop or file-transfer tool that prioritizes speed over raw throughput.