gitmyhub

kcp-go

Go ★ 4.5k updated 1mo ago

A crypto-secure Reliable-UDP library for Golang with FEC support.

A Go library that adds reliable, ordered delivery and optional encryption on top of UDP, giving lower latency than TCP for games, live video, and other real-time apps.

Gosetup: moderatecomplexity 3/5

kcp-go is a Go library that provides reliable, ordered data delivery over UDP (User Datagram Protocol). UDP is a fast but normally unreliable way to send data across a network. TCP, the alternative, provides reliability but adds latency through its connection setup and acknowledgment mechanisms. kcp-go adds ordering, error checking, and guaranteed delivery on top of UDP while keeping response times lower than TCP allows.

The library is designed for situations where speed matters more than bandwidth efficiency, such as online games, live video broadcasts, file synchronization tools, and network acceleration programs. It has been deployed across millions of devices, from low-end home routers to high-end servers. The code is compatible with Go's standard network interfaces, so it can replace a regular TCP connection in existing code without major rewrites.

Beyond basic reliable delivery, kcp-go includes forward error correction using Reed-Solomon codes. This technique sends extra redundancy data alongside each message, allowing the receiver to reconstruct lost packets without waiting for a retransmission. The library also supports packet-level encryption with several algorithm options including AES, Blowfish, and Salsa20. Encryption is applied to the complete packet including headers, making it harder to analyze or tamper with traffic in transit.

On the performance side, the library handles more than 5,000 concurrent connections on a single commodity server. The README documents the design choices behind this: using contiguous memory slices rather than linked lists for cache efficiency, minimizing calls to the system clock, and drawing memory from a global pool to avoid unnecessary allocations. On Linux, batch send and receive system calls are available to reduce per-packet overhead further. The library is licensed under MIT.

Where it fits