dcsimg
Socket setSoTimeout
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   shay_te
Posted On:   Sunday, April 23, 2006 08:09 AM

i open a TelnetClient and communicate to a telnet server (i am using apache commonds) if i set the setSoTimeout to 5 seconds i write and read from the socket and my program do other stuff that take more then 5 seconds for example Thread.sleep(7000); then i write and try to read a again from the socket a "SocketTimeoutException" is thrown. i know for sure that i have data to read. (because if i sleep for 2000 i can read the data) sould i reset the input sream? what sould i do? thanks shay    More>>

i open a TelnetClient and communicate to a telnet server

(i am using apache commonds)

if i set the setSoTimeout to 5 seconds

i write and read from the socket

and my program do other stuff

that take more then 5 seconds

for example Thread.sleep(7000);

then i write and try to read a again from the socket

a "SocketTimeoutException" is thrown.

i know for sure that i have data to read.

(because if i sleep for 2000 i can read the data)




sould i reset the input sream?

what sould i do?




thanks




shay

   <<Less

Re: Socket setSoTimeout

Posted By:   Almagest_FUTT  
Posted On:   Sunday, April 23, 2006 10:15 AM

So, to summarise what you said: you have set up your program to do something specific in a specific case (a timeout after a certain time), and when your program encounters the specified case it does what it has been told to -- and you're asking us what you should do ?


Shall I quote the SO_TIMEOUT Javadoc ? Wouldn't that be too blunt ?



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 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.

Parameters:
timeout - the specified timeout, in milliseconds.
Throws:
SocketException - if there is an error in the underlying protocol, such as a TCP error.
Since:
JDK 1.1
See Also:
getSoTimeout()
About | Sitemap | Contact