Check if the server socket is open on the other side

I would check if the server socket on the server is open. In the client, when I create a socket Socket sock = new Socket(host,port), I check if it opens:

if(sock == null)
    System.out.println("The server is not connected!");
else
    //Doing some task

but I get no result. is there a way to check if the server socket is open on the other side? I tried even the method isConnected(), but nothing

+5
source share
2 answers

If the server is not listening, you will receive a "Disconnected" message in the exception. You will never get zero fromnew

+8
source

- Socket connect() . .

+10

All Articles