If you set a maximum wait time for a socket to receive data 5 seconds

Socket ms = new Socket("127.0.0.1", 1234); ms.setSoTimeout(5000); 

then, on SocketTimeoutException error

java.net.SocketTimeoutException: Read timed out

will the server connection be closed? That is, the socket after such an exception will be closed?

And if the timeout does not install the socket, then such an error will never occur?

    1 answer 1

    Judging by the documentation will not be closed

    If the timeout expires, a java.net.SocketTimeoutException is raised, though the Socket is still valid.

    \

    And if the timeout does not install the socket, then such an error will never occur?

    Yes, it will wait until the OS breaks the connection.