How to find out if TCP Listener is listening?

3

Library that I use: link

Follow the code below:

await client.ConnectAsync(address, port);

The above code is the client and works normal. Let's say the server is off, when I run the above code, it takes little time and I get error:

  

Connection timed out

It takes about 3 minutes to execute this exception. Is there any way to tell if the server is listening before running the above code? Or decrease from 3 minutes to 5 seconds.

Here is the answer on how to get the status: link

    
asked by anonymous 20.03.2018 / 21:07

1 answer

2

You can change the Timeout of the client:

TCPClient.ReceiveTimeout = 5000; 
TCPClient.SendTimeout = 5000;
  

Note that a very short timeout can cause problems during communication.

    
20.03.2018 / 22:08