I'm trying to learn Socket and I'm confused by following text from Oracle's website:
setSoTimeout
public void setSoTimeout(int timeout) throws SocketException
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a non-zero timeout, a
read()
call on theInputStream
associated with this Socket will block for only this amount of time. If the timeout expires, ajava.net.SocketTimeoutException
is raised, though the Socket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.
My questions:
What is
SO_TIMEOUT
?Socket is the endpoint of a connection. If I say
mySocket.setSoTimeout(2000);
Does it mean that I'm blocking reading any input from the Server/Client for this socket for 2000 millisecond and after this time the socket is ready to read data?
What does it mean timeout expire?
What is the option which must be enabled prior to blocking operation?
Infinite Timeout means that the socket doesn't read anymore?