tokio_kcp icon indicating copy to clipboard operation
tokio_kcp copied to clipboard

Never reaches EOF (or 0 bytes read)

Open jeromegn opened this issue 2 years ago • 3 comments

I've been playing with this crate, but I can't get my read loop to stop (when it reads 0 bytes, like in your example).

On the client-side, I'm writing 80 bytes. On the server-side, the first loop iteration reads the whole 80 bytes and then keeps looping, even if my client has been dropped (closed).

I tried various options like stream: false, but couldn't make it work. I think this might be an issue with the async implementation specifically.

Any ideas?

jeromegn avatar Sep 23 '22 18:09 jeromegn

Well, because there is no FIN in KCP, so there is no way for server to know the client have been dropped.

zonyitoo avatar Sep 24 '22 14:09 zonyitoo

https://github.com/Matrix-Zhang/tokio_kcp/blob/b6a95638cfef32f75f400363abd9db13081bb63a/src/session.rs#L143-L168

The server socket will expire after session_expire seconds. So you may try to set it via config.session_expire.

zonyitoo avatar Sep 25 '22 07:09 zonyitoo

Ok, so I should design my representation of data with a delimiter to mark the end of a message.

jeromegn avatar Sep 26 '22 14:09 jeromegn