A Full-Featured Reliable-UDP Library for golang
Go
Latest commit 210b760 Feb 21, 2017 @xtaci committed on GitHub Update README.md

README.md

kcp-go

GoDoc Powered MIT licensed Build Status Go Report Card Coverage Statusd

Claude_Shannon

Introduction

kcp-go is a full-featured Reliable-UDP library for golang. It provides reliable, ordered, and error-checked delivery of a stream of octets between applications running on hosts communicating over an IP network.

Features

  1. Optimized for Online Games, Audio/Video Streaming.
  2. Compatible with skywind3000's C version with optimizations.
  3. Cache friendly and Memory optimized design in golang.
  4. Compatible with net.Conn and net.Listener.
  5. FEC(Forward Error Correction) Support with Reed-Solomon Codes
  6. Packet level encryption support with AES, TEA, 3DES, Blowfish, Cast5, Salsa20, etc. in CFB mode.

Conventions

Control messages like SYN/FIN/RST in TCP are not defined in KCP, you need some keepalive mechanims in the application-level. a real world example is to use some multiplexing protocol over session, such as smux, see kcptun for example.

Documentation

For complete documentation, see the associated Godoc.

Specification

Frame Format

Usage

Client: full demo

kcpconn, err := kcp.DialWithOptions("192.168.0.1:10000", nil, 10, 3)

Server: full demo

lis, err := kcp.ListenWithOptions(":10000", nil, 10, 3)

Performance

  型号名称:   MacBook Pro
  型号标识符:    MacBookPro12,1
  处理器名称:    Intel Core i5
  处理器速度:    2.7 GHz
  处理器数目:    1
  核总数:  2
  L2 缓存(每个核):   256 KB
  L3 缓存:  3 MB
  内存: 8 GB
$ go test -run Speed
new client 127.0.0.1:61165
total recv: 16777216
time for 16MB rtt with encryption 570.41176ms
&{BytesSent:33554432 BytesReceived:33554432 MaxConn:2 ActiveOpens:1 PassiveOpens:1 CurrEstab:1 InErrs:0 InCsumErrors:0 InSegs:42577 OutSegs:42641 OutBytes:48111336 RetransSegs:92 FastRetransSegs:92 LostSegs:0 RepeatSegs:0 FECRecovered:1 FECErrs:0 FECSegs:8514}
PASS
ok      github.com/xtaci/kcp-go 0.600s

Tuning

Q: I'm running > 3000 connections on my server. the CPU utilization is high.

A: A standalone agent or gate server for kcp-go is suggested, not only for CPU utilization, but also important to the precision of RTT measurements which indirectly affects retransmission. By increasing update interval with SetNoDelay like conn.SetNoDelay(1, 40, 1, 1) will dramatically reduce system load.

Who is using this?

  1. https://github.com/xtaci/kcptun -- A Secure Tunnel Based On KCP over UDP.
  2. https://github.com/getlantern/lantern -- Lantern delivers fast access to the open Internet.
  3. https://github.com/smallnest/rpcx -- A RPC service framework based on net/rpc like alibaba Dubbo and weibo Motan.
  4. https://github.com/gonet2/agent -- A gateway for games with stream multiplexing.

Links

  1. https://github.com/xtaci/libkcp -- FEC enhanced KCP session library for iOS/Android in C++
  2. https://github.com/skywind3000/kcp -- A Fast and Reliable ARQ Protocol
  3. https://github.com/klauspost/reedsolomon -- Reed-Solomon Erasure Coding in Go

Support

You can support this project by the following methods:

  1. Vultr promotion code:
    http://www.vultr.com/?ref=6897065

  2. Paypal
    https://www.paypal.me/xtaci

Your name or github name will be listed on this page by default.