What is the best way to automatically connect Tcpclient to a server when it is disconnected (for example, by the server itself)?
The code I use is:
public void ClientWork() { TcpClient client = new TcpClient(); try { try { client.Connect(ip, port); } catch(Exception ex) { logger.ErrorFormat("client.Connect: {0}", ex.Message); return false; } NetworkStream ns = client.GetStream(); byte[] buff; while (__bRunning) { buff = new byte[1000]; ns.Read(buff, 0, 1000); string line = System.Text.Encoding.Default.GetString(buff); }
I am using C # .NET
source share