BrandonPotter / SimpleTCP

Straightforward .NET library to handle the repetitive tasks of spinning up and working with TCP sockets (client and server).
Apache License 2.0
363 stars 108 forks source link

Is there a reconnection mechanism? #35

Open chengwengao opened 6 years ago

chengwengao commented 6 years ago

Is there a reconnection mechanism?

davi2td commented 6 years ago

Don't believe so, that would be something you'd have to do on your own, in general, you'd want to know why you got disconnected, or never connected, before arbitrarily reconnecting. Or at least limit retries after a period... But to answer your question you'd hook into the ClientDisconnected event and reconnect.

chengwengao commented 6 years ago

Thanks for your advice, I started trying to write for myself, including client / server disconnection or shutdown and restart, but there's always no guarantee that everything is working well, so I'd like to rely on a mature framework. Your project example is very simple, but I didn't find any details about the reconnection. Later I found a faster SCS(simle client server on codeproject). If Supersocket has strong reconnection performance on the server side, so does the reconnection performance on the client side (its server side is also excellent. I hope the author can also add related reconnect features later, so that more beginners can start faster.The SCS project link is as follows:https://www.codeproject.com/Articles/153938/TCP-Server-Client-Communication-Usage

BrandonPotter commented 6 years ago

Reconnect is tough because you never really know if the TCP connection is really closed until you try and send something and it fails. There’s another related issue to this regarding the ClientDisconnected event not firing.

We’ve thought about a heartbeat type packet but it would really only be useful when using this library on both client and server side...

chengwengao commented 6 years ago

I seem to be beginning to understand what you're saying about using heartbeat packets on both the client and the server to detect if the client is really disconnected from the server, although the SCS framework supports reconnection. But after testing that losing packets in high concurrency is serious, which may have something to do with what you say about repeated reconnections, I tried another framework named TCP Socket Off-the-shelf in CodeProject. It has a very low rate of packet loss, but the connection is automatically closed after running for a while and cannot be reconnected.