Reliably reconnect to the server TCPClient C#
I am having trouble reconnecting a TCPClient 开发者_StackOverflow(actual class name from C#) to its server. Is there a well defined way of doing this? Do I need to manage the tcp connection at the server as well if a client is trying to reconnect on the same port,
Thanks!
Most of the time you should do it the same way that you first connected to it. Just don't forget to close the connection before trying to reconnect.
Maybe a little bit more info is needed because maybe your trouble is elsewhere.
Do you call a simple "Receive" command and then close the connection and try to reconnect later. Or are you trying to "BeginReceived" (Async connection) then you would need to handle the ObjectDisposed Exception when you will disconnect and after that reconnect
精彩评论