- Notifications
You must be signed in to change notification settings - Fork29
Unit-X/kcp-cpp
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Simple C++ wrapper of theKCP protocol.
Requires cmake version >=3.10 andC++17
Release:
mkdir buildcd buildcmake -DCMAKE_BUILD_TYPE=Release ..cmake --build. --config Release
Debug:
mkdir buildcd buildcmake -DCMAKE_BUILD_TYPE=Debug ..cmake --build. --config Debug
Output:
(platform specific)kcpnet.(platform specific)
(Linux/MacOS -> libkcpnet.a)
(Windows -> kcpnet.lib)
//----------//Server ---//----------//Create the server//1. Data from server callback//2. Client disconnect callback//3. Validate new client callback//4. Listening interface//5. Listening port//6. Optional contextKCPNetServer lKcpServer;lKcpServer.configureKCP(gotDataServer, noConnectionServer, validateConnection,"127.0.0.1",8000,nullptr);//Send data to the client//1. Pointer to the data//2. The size of the data//3. The pointer to the KCPContext you got when accepting the clientlKcpServer.sendData((constchar*)lData.data(),4000,gRetainThis.get());//----------//Client ---//----------//Create the client//1. The settings struct//2. Got data from server//3. Lost connection to server//4. Connect to interface//5. Connect to port//6. Connection ID (Must be set identical on the server see -> validateConnection)//7. Optional contextKCPNetClient lKcpClient;KCPSettings lSettingsClient;configureKCP(lSettingsClient, gotDataClient, noConnectionClient,"127.0.0.1",8000,10,nullptr);//Send data to the server//1. Pointer to the data//2. The size of the datalKcpClient.sendData((constchar*)lData.data(),4000);//Please see KCP documentation for details.classKCPSettings {public:boolmNodelay =false;//No delay mode. False: Off / True: On.intmInterval =100;//KCP update interval in msintmResend =0;//Retransmit when missed mResend number ACK (Default value is 0)boolmFlow =false;//Flow control, False: Off / True: On.intmMtu =1472;//Maximum payload in a single UDP datagramintmSndWnd =32;//Send window sizeintmRcvWnd =32;//Receive window size //The doc says 32 the code says 128};
- Step1
Add this in your CMake file.
#Include kcpnetinclude(ExternalProject)ExternalProject_Add(project_kcpnet GIT_REPOSITORY https://github.com/Unit-X/kcp-cpp GIT_SUBMODULES "" UPDATE_COMMAND "" SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/kcpnet BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/kcpnet GIT_PROGRESS 1 BUILD_COMMAND cmake --build ${CMAKE_CURRENT_SOURCE_DIR}/kcpnet --config ${CMAKE_BUILD_TYPE} --target kcpnet STEP_TARGETS build EXCLUDE_FROM_ALL TRUE INSTALL_COMMAND "" )add_library(kcpnet STATIC IMPORTED)add_library(kcp STATIC IMPORTED)IF (WIN32) set_property(TARGET kcpnet PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/kcpnet/${CMAKE_BUILD_TYPE}/kcpnet.lib) set_property(TARGET kcpnet PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/kcpnet/kcp/${CMAKE_BUILD_TYPE}/kcp.lib)ELSE() set_property(TARGET kcpnet PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/kcpnet/libkcpnet.a) set_property(TARGET kcp PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/kcpnet/kcp/libkcp.a)ENDIF()add_dependencies(kcpnet project_kcpnet)include_directories(${CMAKE_CURRENT_SOURCE_DIR}/kcpnet/)include_directories(${CMAKE_CURRENT_SOURCE_DIR}/kcpnet/kcp/)- Step2
Link your library or executable.
target_link_libraries((your target) kcpnet kcp (the rest you want to link))- Step3
Add header file to your project.
#include "KCPNet.h"Anders Cedronius for creating the C++ wrapper
anders.cedronius(at)edgeware.tv
MIT
ReadLICENCE for details
About
C++ Wrapper around KCP
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Contributors2
Uh oh!
There was an error while loading.Please reload this page.
