This week's book giveaway is in the Android forum.
We're giving away four copies of Android Programming: The Big Nerd Ranch Guide and have Bill Phillips & Chris Stewart on-line!
See this thread for details.
Win a copy of Android Programming: The Big Nerd Ranch Guide this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

URLConnection timeout  RSS feed

 
f jimenez
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello guys im back.

i have an applet that connects to a servlet in the server. the connection used is URLConnection. now i want that if this applet can't connect/can't get data from the server at a given time, the user has the option to abort connection or continue...

how do i do this using URLConnection?

codes will be very much appreciated

thanks...
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
URLConnection has a few methods with "timeout" in their names; check the javadocs what exactly they do.

Alternatively, you can run a Timer in the applet which after a certain amount of time fires, and if the connection hasn't returned anything by that point, do something about it.
 
f jimenez
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks ulf.

how can you do the second option? pls help...
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the java.util.Timer and TimerTask classes.
 
f jimenez
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks...

i just have another question though. what exactly does timeout do? does the connection stop when timeout is fired?

how can i reconnect it? to reconnect it, does it mean i have to make the same process again?

thansk a lot.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what exactly does timeout do? does the connection stop when timeout is fired?

Yes, it's terminated.
how can i reconnect it?

You need to make a new connection, in the same way you did the first one.
 
f jimenez
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, thats exactly what i did... thanks a lot...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!