Skip to content

KCP

A small C library that adds fast, reliable retransmission on top of UDP.

Stars
17k
Forks
2.6k
Licence
MIT
Language
C
Last update
5 months ago
Type
Library

What it is

KCP is a networking algorithm written in C that makes UDP packets arrive reliably, by resending lost data and acknowledging receipt. It trades some extra bandwidth for lower latency than TCP, according to the README. It does not send or receive packets itself; the program using it supplies the UDP send and receive code and the clock.

  • Add reliable, ordered-or-acknowledged delivery to a custom UDP game or chat protocol
  • Accelerate a tunnel or port-forwarding service over UDP, as projects like kcptun do
  • Speed up video or audio streaming between endpoints where latency matters more than bandwidth

Great for

  • Developers building their own UDP-based protocol who need reliable delivery
  • Projects that need lower latency for small, time-sensitive messages
  • Developers embedding a protocol stack in C or porting it to other languages
  • Teams building games or real-time media transport that can accept extra bandwidth use

Not ideal for

  • People who just want a finished app or tool; KCP is a building block with no user interface
  • Projects where bandwidth is tight, since the README says it wastes 10%-20% more bandwidth than TCP
  • Anyone unwilling to write the UDP send/receive glue and call update in a loop
Step-by-step guide: how to use KCPInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Clone and build from source

    You'll need: A C compiler · Git

    Clone the repository

    git clone https://github.com/skywind3000/kcp
  2. 2

    Run it

    • Copy ikcp.h and ikcp.c into your project
    • Create a KCP object with ikcp_create(conv, user)
    • Set kcp->output to a function that sends UDP packets
    • Call ikcp_update(kcp, millisec) on a regular interval and ikcp_input when UDP packets arrive
    • Use ikcp_send and ikcp_recv to move data
  3. 3

    Get the most out of it

    • Use ikcp_nodelay to switch between normal mode (0, 40, 0, 0) and the faster mode shown in the README (1, 10, 2, 1)
    • Raise the window size with ikcp_wndsize, since the default is 32 packets
    • Adjust the MTU with ikcp_setmtu if your network path differs from the default 1400 bytes
    • Read the wiki pages linked in the README for best practices, TCP server integration, and flow control

Downloads

Strengths

  • Small footprint: the README says the whole protocol is two source files, ikcp.h and ikcp.c
  • Does no system calls internally and takes the clock from the caller, which makes it easy to fit into existing event loops
  • Many ports exist in other languages (Go, Rust, C#, Java, Python), as listed in the README

Trade-offs

  • Uses more bandwidth than TCP by design, per the README's 10%-20% figure
  • Does not handle packet transmission, MTU discovery, or encryption; those are the caller's job, with encryption covered only by a linked wiki page
  • Requires careful integration (calling update, input, and send correctly), so it is not plug-and-play

How it compares

ProjectStarsTypeLevelUpdatedBest for
kcp (this)17kLibraryadvanced5 months agoDevelopers building their own UDP-based protocol who need reliable delivery
quic-go11.8kLibraryadvanced4 days agoGo developers building servers or clients that need QUIC or HTTP/3
gost18.3kCLIintermediate2 months agoDevelopers who want a single binary to run a local or remote SOCKS5 or HTTP proxy
srs29.4kAppintermediate6 days agoDevelopers building live streaming backends that need several delivery protocols
vcpkg27.6kDev toolintermediate4 days agoC and C++ developers who need third-party libraries in their projects
tree-sitter27.4kLibraryadvanced4 days agoDevelopers building code editors or IDE features that need to understand source code as it changes

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.