Reputation: 31
I am developing one tcp server application using tcp listener in Windows service using c#.
After starting my service it works fine and accepts new clients. After some time when ever the new client is trying to connect to server it gives the following exception:
connection failed, is the server running? No connection could be made because the target machine actively refused it.
At that time the service is in running state only.
How can I verify the tcp server is in listening state or not?
Upvotes: 3
Views: 3632
Reputation: 311039
If your server is still running and hasn't close the listening socket, it is still in listening state. However if the platform is Windows and your server's backlog queue is full, a windows will refuse further connections. That means that your server is slow accepting new connections.
Upvotes: 1
Reputation: 5135
netstat -ab
This command will give you information about all active connections with name of the programs.
Another option is TcpView from Mark Russinovich
Upvotes: 1
Reputation: 8288
If you want to check if the server is listening, and the server is Windows, you can simply use (e.g. 8888 is your listening port)
netstat -ano|findstr "8888"
Then you'll see the PID of your server instance.
In addition, if you want to check why the TCP connection attempt is fail, you could use Wireshark to capture all the TCP packets between server & client, then the reason will be quite clear.
E.g. if the server has reached the limitation of open socket number, you'll see a SIN from client to server, and how the server is responding.
Upvotes: 0
Reputation: 611
Not sure if you mean programatically or not, but for the latter, you can try telnet: telnet host port
telnet yahoo.com 80
telnet localhost 3306
etc.
Upvotes: 0