Matrix-Zhang / tokio_kcp

A Kcp implementation for tokio
MIT License
176 stars 44 forks source link

Never reaches EOF (or 0 bytes read) #18

Closed jeromegn closed 6 months ago

jeromegn commented 2 years ago

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?

zonyitoo commented 2 years ago

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

zonyitoo commented 2 years ago

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.

jeromegn commented 2 years ago

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