unit-x / kcp-cpp Goto Github PK
View Code? Open in Web Editor NEWC++ Wrapper around KCP
License: MIT License
C++ Wrapper around KCP
License: MIT License
When receiving a relatively large data packet (larger than 8192), the last packet will block for 8 to 10 seconds at mKissnetSocket.recv(receiveBuffer).
const uint64_t tickStart = GetTickCount64();
auto[received_bytes, status] = mKissnetSocket.recv(receiveBuffer);
const auto tick = GetTickCount64() - tickStart;
if (tick > 1000) {
KCP_LOGGER(false, LOGG_NOTIFY, "Recv Time: " << tick); // <---------- 10 Second !!!!
}
The server is developed using kcp-go with the following parameters:
kcpConn.SetNoDelay(1, 10,2,1)
kcpConn.SetWindowSize(128, 128)
kcp-cpp:
KCPSettings lSettingsClient;
lSettingsClient.mNoDelay = true;
lSettingsClient.mInterval = 10;
lSettingsClient.mResend = 2;
lSettingsClient.mFlow = false;
lSettingsClient.mMtu = 1400;
lSettingsClient.mSndWnd = 128;
lSettingsClient.mRcvWnd = 128;
KCP-cpp test
Connecting IP:port > 127.0.0.1:61263
The server is not active.
The server timed out a client.
Does it support communication as a client and kcp-go server? My own test results are not good.
I try to use this main.cpp to connect kcp-go(golang) server,But failed
kcp-go can't accept any data from client
and kcp-go send data to client,but client can't get any data
main.cpp:
`KCPNetClient lKcpClient;
KCPSettings lSettingsClient;
if(lKcpClient.configureKCP(lSettingsClient,
gotDataClient,
noConnectionClient,
"127.0.0.1",
12345,
10,
nullptr)) {
std::cout << "Failed to configure the KCP Client" << std::endl;
}
lKcpClient.sendData((const char*)lData.data(), 4000);`
main.go:
`package main
import (
"log"
"github.com/xtaci/kcp-go/v5"
)
func main() {
if listener, err := kcp.ListenWithOptions("127.0.0.1:12345", nil, 10, 3); err == nil {
// spin-up the client
for {
s, err := listener.AcceptKCP()
s.SetNoDelay(1, 10, 2, 1)
if err != nil {
log.Fatal(err)
}
go handleEcho(s)
}
} else {
log.Fatal(err)
}
}
// handleEcho send back everything it received
func handleEcho(conn *kcp.UDPSession) {
buf := make([]byte, 4096)
for {
n, err := conn.Read(buf)
if err != nil {
log.Println(err)
return
}
println("get:" + string(buf[:n]))
n, err = conn.Write(buf[:n])
if err != nil {
log.Println(err)
return
}
}
}
`
I found that after the kcpClient triggers the disconnection (noConnectionClient), when I call sendData again to send data, there is no response in the gotDataClient callback function after the server responds.
In the KCP NetServer::netWorkerServer function, we start a network thread and exit if there are no incoming messages. That is, when the server starts, it will shut down. This is very strange, considering that the server must work constantly and wait for clients to connect
while (true) {
auto[received_bytes, status] = mKissnetSocket.recv(receiveBuffer,0, &receiveConnection);
if (!received_bytes || status != kissnet::socket_status::valid) {
KCP_LOGGER(false, LOGG_NOTIFY, "serverWorker quitting");
break;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.