kcp-go is a Reliable-UDP library for Go that delivers ordered, error-checked stream communication over UDP packets with built-in encryption and forward error correction.
The library solves the problem of achieving low-latency, reliable communication in scenarios where TCP's overhead is unacceptable. It implements the KCP protocol, which prioritizes speed over strict ordering by using a faster retransmission strategy. The approach includes forward error correction using Reed-Solomon codes to recover lost packets without retransmission, packet-level encryption supporting multiple cipher algorithms in CFB mode and AEAD modes for anonymous packet delivery, and careful memory management optimized for cache efficiency. The implementation uses a fixed number of goroutines across the entire server to minimize context-switching overhead and includes platform-specific optimizations like sendmmsg and recvmmsg on Linux.
Developers should choose this tool for latency-sensitive applications such as online games, live broadcasting, file synchronization, and network acceleration where TCP's latency characteristics are problematic. The library is designed to handle over five thousand concurrent connections on a single commodity server. It provides a drop-in replacement for net.TCPConn, implementing the standard net.Conn and net.Listener interfaces, which simplifies integration into existing Go codebases. The tool suits projects requiring high throughput with low latency and those operating in unreliable network conditions where packet loss is common.
The project maintains active development with regular updates to its codebase. Documentation is comprehensive, including detailed Godoc references and design documentation covering key considerations like memory management, timing accuracy, and packet clocking strategies. The README includes performance benchmarks, flame graphs for profiling analysis, and practical examples demonstrating usage patterns. The project has seen real-world deployment across millions of devices ranging from low-end MIPS routers to high-end servers, with documented use cases in production systems.