• Post Reply Bookmark Topic Watch Topic
  • New Topic

Timeout(URGENT)

 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have socket program which sends file to the server. After it send, I want response back from the server. The response time out I want to set 20 seconds. i.e. I want to wait only 20 seconds for the response from the server.How Can I do that? Can I do following:
for(int i = 0; i <= 20; i++)
{
try
{
if(in.ready())//in is BufferedReader
{
//I mean get response do something...
}
}
}
Thanks,
Angela
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Angela,
Can you do this? :


Hope this helps
Michael Morris
SCJP2
 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean like this:
for(int i = 0; i <= 20; i++)
{
try
{
Thread.sleep(20000);
if(in.ready())//in is BufferedReader
{
//I mean get response do something...
}
}
Catch(Exception e){}
}
Thanks,
Angela
 
Lewin Chan
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm just going to use a code example

in.read() will block until there is
a) data to be read
b) timeout is exceeded
e) EOF is reached.
brgds
Lewin
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!