Lightweight KCP Session Implementation - kcpp
kcpp
truly enables you to use KCP just by including a single header file and writing a few lines of code, without having to worry about how to organize the code to adapt to KCP.
- You only need to include the single header file
kcpp.h
. - You only need to call
KcpSession::Send
,KcpSession::Recv
, andKcpSession::Update
to complete UDP connection state management, session control, and RUDP protocol scheduling.
What is KCP?
KCP is a high-performance, reliable, and lightweight transport layer protocol designed to accelerate UDP-based data transmission. It provides an efficient alternative to TCP while maintaining UDP’s low-latency benefits. Originally developed by skywind3000, KCP is widely used in real-time applications such as gaming, live streaming, VPNs, and P2P networking.
Features
- Single-header-only
- Session implementation
- Dynamic redundancy
- Two-channel
- Reliable
- Unreliable
kcpp Examples
- realtime-server: A real-time dedicated game server (FPS / MOBA).
- realtime-server-ue4-demo: A UE4 state synchronization demo for the real-time server. Video Preview
kcpp Usage
The main loop is supposed to be as follows:
Game.Init(); |
The Recv
, Send
, and Update
functions of kcpp are guaranteed to be non-blocking.
Please read TestKcppClient.cpp and TestKcppServer.cpp for some basic usage examples.
KCP Source Code Annotations
This project also comes with an annotated version of the KCP source code, ikcp.h
and ikcp.c
. It can be regarded as another detailed explanation of KCP, which is convenient for self-study and helps others get started more quickly. The original code is from: https://github.com/skywind3000/kcp. Thanks to skywind3000 for bringing such a concise and excellent project.
Readers interested in open-source projects for real-time combat games like FPS / MOBA can also visit realtime-server. Welcome to communicate.
Note: Tabs are used for indentation in the project, and tab is set to 2 spaces.
Almost every paragraph has annotations, and key data structures are accompanied by diagrams. For example:
... |
轻量级的kcp会话实现-kcpp
kcpp
真正实现了只需要包含一个头文件再随意写几行代码就可以用上kcp, 而无需烦心如何组织代码来适配kcp
- 只需包含
kcpp.h
这一个头文件即可 - 只需调用
KcpSession::Send
和KcpSession::Recv
和KcpSession::Update
即可完成UDP的链接状态管理、会话控制、 RUDP协议调度
kcp源码注释
本项目还附了一个注释版的kcp源码 ikcp.h
和 ikcp.c
, 算是另一种的 kcp详解, 方便自己学习也为大家更快的上手, 原始代码来自: https://github.com/skywind3000/kcp , 感谢 skywind3000 带来这么短小精悍的好项目
对 FPS / MOBA 类实时对战游戏开源项目感兴趣的读者还可以移步 realtime-server , 欢迎交流
注 : 项目中使用 tab 缩进且设置了tab = 2 space
几乎每个段落都有注释, 且关键数据结构还带有图解, 比如 :
... |