How can I tell if a socket is "listening" to the server side?

3

When I use the isConnected() function of java.net.Socket ", on the client side, and it returns me true I can be sure that the server Are you listening? Otherwise how can I know? Just with a wait time between establishing a connection and getting "to write"?

PS: I put the Android tag because I do not know if it has influence.

    
asked by anonymous 25.05.2017 / 16:22

1 answer

2

Good evening, Jorge,

As the documentation says: Note: Closing the socket does not clear its connection state, which means this method will return true for a closed socket (see isClosed () if it was successfuly connected prior to being closed.

When a socket connection closes it does not change the state of the object, so it remains true.

The best approach is to implement an ACK on your client / server. Your client makes an ACK for your server and it responds. If an error occurs in writing on the socket you know that the connection has been lost and connects again.

Abs

    
27.05.2017 / 03:40