Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

C++ Wrapper around KCP

License

NotificationsYou must be signed in to change notification settings

Unit-X/kcp-cpp

Repository files navigation

alt text

Simple C++ wrapper of theKCP protocol.

alt text

Build

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)

Current build status

kcpcpp_ubuntu

kcpcpp_macos

kcpcpp_win

Usage

//----------//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};

Using KCP - CPP in your CMake project

  • 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"

Credits

Anders Cedronius for creating the C++ wrapper

anders.cedronius(at)edgeware.tv

License

MIT

ReadLICENCE for details

About

C++ Wrapper around KCP

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp