Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

What does setSoTimeout ( int timeout ) in Socket class do?

807598Nov 3 2006 — edited Jan 4 2007
In the API, this method is describe as:

Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a non-zero timeout, a read() call on the InputStream associated with this Socket will block for only this amount of time. If the timeout expires, a java.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.

I have problem understanding it. It say that the Socket will block for the amount of time set. What does 'block' means? Does it mean that the socket waits for the predefined time to receive data packet? Or just wait to receive data packet? Or both? Or I've got it wrong altogether?

Sorry but as you can see, I'm still clueless about many things regarding Java. Thank you for your time and patience.

Message was edited by:
Toc
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 1 2007
Added on Nov 3 2006
11 comments
1,820 views