KCP sample not working
Closed this issue · 6 comments
The kcp sample doesn't seem to be working.
Is that right?
fixed , pls update
Thanks, i think it's a great job to make things simpler. Hope your project stay active for a long time.
If you allow me, id like to ask one thing and suggest others:
Question:
Can you give me an example on how to use more than one thread with kcp (listener and client)?
Sugestions:
- I think it can have alternative methods to work with binary data ( like send(char* data, int size) ).
- And a way to customize KCP options (nodelay, resend...)
Another thing, after a few seconds the client stop receiving messages from the server...
I'm trying to do a socks proxy with a kcp tunnel.
The hearthbeat is ok, but the client does not receive messages.
Log from server side:
[DEBUG] send:149 send user message on status 2
[DEBUG] send:149 send user message on status 2
[DEBUG] send:149 send user message on status 2
[DEBUG] send:149 send user message on status 2
[DEBUG] send:149 send user message on status 2
[DEBUG] send:149 send user message on status 2
[DEBUG] send:149 send user message on status 2
[DEBUG] operator():83 received data 120 from 127.0.0.1:47416
[DEBUG] check_control_message:350 check shakehand status is 2, type is 82
[DEBUG] handle_receive:457 handle receive data 120
Log from client side:
[DEBUG] operator():436 receive message length 79
[DEBUG] check_control_message:350 check shakehand status is 2, type is 81
[DEBUG] handle_receive:457 handle receive data 79
[DEBUG] handle_receive:460 kcp input command 0
[WARN] handle_receive:474 no more kcp fragments -3
[DEBUG] operator():436 receive message length 1400
[DEBUG] check_control_message:350 check shakehand status is 2, type is 81
[DEBUG] handle_receive:457 handle receive data 1400
[DEBUG] handle_receive:460 kcp input command 0
[WARN] handle_receive:474 no more kcp fragments -3
[DEBUG] operator():436 receive message length 79
[DEBUG] check_control_message:350 check shakehand status is 2, type is 81
[DEBUG] handle_receive:457 handle receive data 79
[DEBUG] handle_receive:460 kcp input command 0
[WARN] handle_receive:474 no more kcp fragments -3
[DEBUG] operator():436 receive message length 1400
[DEBUG] check_control_message:350 check shakehand status is 2, type is 81
[DEBUG] handle_receive:457 handle receive data 1400
Found the problem, you can get the next message size before reading it with a so short limit.
int size = ikcp_peeksize(kcp);
if (size <= 0) {
wlog("no more kcp fragments size {}", size);
// ikcp_log(kcp,"kcp input error");
break;
}
char kcpBuf[size] = "";
int32_t kcp_recvd_bytes = ikcp_recv(kcp, kcpBuf, sizeof(kcpBuf));
it's easy to use multi threads . just create multi eventworkers. I will add a sample later.
that's great to use ikcp_peeksize to get the message size , thanks.
since kcp is based on udp, it can't support multi-threads for connections based on logic id , I add multi-threads support on event worker. not test carefully, you can try it.