All Projects → no5ix → Kcpp

no5ix / Kcpp

A single-header-only kcp session implementation (dynamic redundancy + reliable udp/unreliable channel) & A annotated kcp. 一个单头文件的kcp会话实现(动态冗余+可靠udp/非可靠双通道), 另附一个注释版kcp.

Programming Languages

c
50402 projects - #5 most used programming language

Labels

Projects that are alternatives of or similar to Kcpp

fuso
一款体积小, 快速, 稳定, 高效, 轻量的内网穿透, 端口转发工具 支持多连接,级联代理,传输加密 (A small volume, fast, stable, efficient, and lightweight intranet penetration, port forwarding tool supports multiple connections, cascading proxy, and transmission encryption)
Stars: ✭ 1,132 (+1043.43%)
Mutual labels:  kcp
gost
GO Simple Tunnel - a simple tunnel written in golang
Stars: ✭ 154 (+55.56%)
Mutual labels:  kcp
Yasio
A multi-platform support c++11 library with focus on asio (asynchronous socket I/O) for any client application.
Stars: ✭ 483 (+387.88%)
Mutual labels:  kcp
nysocks
Nysocks binds kcp and libuv to provide an aggressive tcp tunnel in nodejs.
Stars: ✭ 78 (-21.21%)
Mutual labels:  kcp
kcp-dotnet
KCP dotNet Core implementation
Stars: ✭ 26 (-73.74%)
Mutual labels:  kcp
Kcp Go
A Crypto-Secure, Production-Grade Reliable-UDP Library for golang with FEC
Stars: ✭ 3,177 (+3109.09%)
Mutual labels:  kcp
ap-kcp
用于穿透恶劣网络环境的高性能可靠传输协议,基于 KCP 优化和修改,使用 Rust 实现
Stars: ✭ 121 (+22.22%)
Mutual labels:  kcp
Realtinet
A fast tcp/udp net lib, based on muduo + kcp. 一个快速的tcp/udp网络库, 基于 muduo + kcp .
Stars: ✭ 46 (-53.54%)
Mutual labels:  kcp
leafltd
leafltd 简介 leafltd是Golang语言社区的项目集合控制项目,其中包含:leaf社区版本,帧同步游戏服务器,H5游戏服务器,KCP,gRPC项目等
Stars: ✭ 78 (-21.21%)
Mutual labels:  kcp
Xkcptun
xkcptun is kcp tunnel for OpenWRT&LEDE, implemented in c language
Stars: ✭ 419 (+323.23%)
Mutual labels:  kcp
kcp erlang
A Reliable-UDP Library for erlang
Stars: ✭ 24 (-75.76%)
Mutual labels:  kcp
jwEngine
A cross-platform C++<->lua server quick solution
Stars: ✭ 226 (+128.28%)
Mutual labels:  kcp
Kcp Csharp
KCP - A Fast and Reliable ARQ Protocol
Stars: ✭ 278 (+180.81%)
Mutual labels:  kcp
CosmosFramework
CosmosFramework is a lightweight plug-in Unity development framework . Has a rich Unity method extensions and toolchain. async/await syntax support, multi-network channel support.Long term support for this project
Stars: ✭ 176 (+77.78%)
Mutual labels:  kcp
Gsnova
Private proxy solution & network troubleshooting tool.
Stars: ✭ 509 (+414.14%)
Mutual labels:  kcp
libuvpp
minimal change of libuv for p2p networking
Stars: ✭ 22 (-77.78%)
Mutual labels:  kcp
gost
GO Simple Tunnel - a simple tunnel written in golang
Stars: ✭ 8,395 (+8379.8%)
Mutual labels:  kcp
Vproxy
1) proxy: LB,DNS,Socks. 2) k8s: CRD and Controllers. 3) sdn: L3 Stackable Virtual Switch.
Stars: ✭ 88 (-11.11%)
Mutual labels:  kcp
Ijjs
a lightweight js runtime for IOT(一个面向物联网的JS运行时)
Stars: ✭ 38 (-61.62%)
Mutual labels:  kcp
Kcp
KCP C#版。线程安全,运行时无alloc,对gc无压力。
Stars: ✭ 294 (+196.97%)
Mutual labels:  kcp

QQ群

因为 KCP 官方群已经满了, 可以加群 496687140

轻量级的kcp会话实现-kcpp

kcpp真正实现了只需要包含一个头文件再随意写几行代码就可以用上kcp, 而无需烦心如何组织代码来适配kcp

  • 只需包含 kcpp.h 这一个头文件即可
  • 只需调用 KcpSession::SendKcpSession::RecvKcpSession::Update 即可完成UDP的链接状态管理、会话控制、 RUDP协议调度

Features

  • single-header-only
  • session implementation
  • dynamic redundancy
  • two-channel
    • reliable
    • unreliable

kcpp Examples

kcpp Usage

the main loop was supposed as:

Game.Init()

// kcpp init
kcpp::KcpSession myKcpSess(
    KcpSession::RoleTypeE,
    std::bind(udp_output, _1, _2),
    std::bind(udp_input),
    std::bind(timer));

while (!isGameOver)
	myKcpSess.Update();

    while (myKcpSess.Recv(data, len))
        if (len > 0)
            Game.HandleRecvData(data, len)
        else if (len < 0)
            Game.HandleRecvError(len);

        if (myKcpSess.CheckCanSend())
            myKcpSess.Send(data, len)
        else
            Game.HandleCanNotSendForNow()

    Game.Logic()
    Game.Render()

The Recv/Send/Update functions of kcpp are guaranteed to be non-blocking. Please read TestKcppClient.cpp and TestKcppServer.cpp for some basic usage.

kcp源码注释

本项目还附了一个注释版的kcp源码 ikcp.hikcp.c, 算是另一种的 kcp详解, 方便自己学习也为大家更快的上手, 原始代码来自: https://github.com/skywind3000/kcp , 感谢 skywind3000 带来这么短小精悍的好项目

对 FPS / MOBA 类实时对战游戏开源项目感兴趣的读者还可以移步 realtime-server , 欢迎交流

注 : 项目中使用 tab 缩进且设置了tab = 2 space

几乎每个段落都有注释, 且关键数据结构还带有图解, 比如 :

...
//
//	kcp发送的数据包设计了自己的包结构,包头一共24bytes,包含了一些必要的信息,具体内容和大小如下:
//	
//	|<------------ 4 bytes ------------>|
//	+--------+--------+--------+--------+
//	|  conv                             | conv:Conversation, 会话序号,用于标识收发数据包是否一致
//	+--------+--------+--------+--------+ cmd: Command, 指令类型,代表这个Segment的类型
//	|  cmd   |  frg   |       wnd       | frg: Fragment, 分段序号,分段从大到小,0代表数据包接收完毕
//	+--------+--------+--------+--------+ wnd: Window, 窗口大小
//	|                ts                 | ts: Timestamp, 发送的时间戳
//	+--------+--------+--------+--------+
//	|                 sn                | sn: Sequence Number, Segment序号
//	+--------+--------+--------+--------+
//	|                una                | una: Unacknowledged, 当前未收到的序号,
//	+--------+--------+--------+--------+      即代表这个序号之前的包均收到
//	|                len                | len: Length, 后续数据的长度
//	+--------+--------+--------+--------+
//
...

//---------------------------------------------------------------------
// ...
//	rcv_queue	接收消息的队列, rcv_queue的数据是连续的,rcv_buf可能是间隔的
//	nrcv_que // 接收队列rcv_queue中的Segment数量, 需要小于 rcv_wnd
//	rcv_queue 如下图所示
//	+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
//	... | 2 | 3 | 4 | ............................................... 
//	+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
//              ^              	        ^                      	^        
//              |                      	|                      	|        
//           rcv_nxt           	rcv_nxt + nrcv_que      rcv_nxt + rcv_wnd		
//
//	snd_buf 发送消息的缓存
//	snd_buf 如下图所示
//	+---+---+---+---+---+---+---+---+---+---+---+---+---+
//	... | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ...........
//	+---+---+---+---+---+---+---+---+---+---+---+---+---+
//              ^               ^               ^
//              |               |               |
//           snd_una         snd_nxt    snd_una + snd_wnd	
//
//
//	rcv_buf 接收消息的缓存
//	rcv_buf 如下图所示, rcv_queue的数据是连续的,rcv_buf可能是间隔的
//	+---+---+---+---+---+---+---+---+---+---+---+---+---+
//	... | 2 | 4 | 6 | 7 | 8 | 9 | ...........
//	+---+---+---+---+---+---+---+---+---+---+---+---+---+	
//
...
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].