I'm running a server on a linux kernel, which starts listening to a port and then crashes (this is not subject here). When I then try to establish a connection from some client using the following code, it looks as if everything is working: The TcpClient gets connected immediately and the send operation succeeds. However, I obviously will never get a response.
TcpClient tcpClient = new TcpClient();
tcpClient.Connect(new IPEndPoint(new IPAddress(new byte[] { 192,168,0,1 }), 123));
if (tcpClient.Connected)
{
Console.WriteLine("Connected");
client.NoDelay = true;
NetworkStream stream = tcpClient.GetStream();
stream.Write(new byte[] { 0 }, 0, 1);
stream.Flush();
Console.WriteLine("Sent");
}
How can I determine if the connection is actually open? When the client now tries to do send a command and waits for the response, it will block until the timeout.
The actual code is part of a wrapper around TcpClient which should handle the connection, send messages and receive the responses. It has no idea about the underlying protocol (so send anything and wait for a response seems not useful...)