• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URLConnection with time interval specified...?

 
prabhu pandurangan
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Members,

I have to connect a URL; but for only certain time interval. Now im using UrlConnection.connect(); But it loops around for one or more attempt whether it could make a connection. Instead i need to connect for certain time interval say 3 seconds; if the url specified is connected within the time interval; it should return 'true' or if it fails to connect the url with in the time interval specified it should return 'false'.

I need a sample java code to perform this action.


Regards,
Prabhu.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you checked the setConnectTimeout method?
 
prabhu pandurangan
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Rob

URL url = new URL(urlName);
URLConnection connection = url.openConnection();
connection.connect();

This is the code im using; how to use setConnectTimeOut();
before im attempting to connect() or after that.

 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Obviously before, otherwise the call to connect() will not know about the new timeout.
 
prabhu pandurangan
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Rob

Thank you very much Rob. I have done it and my issue has been solved.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic