GeeCON Prague 2014*
The moose likes Applets and the fly likes URLConnection timeout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Applets
Bookmark "URLConnection timeout" Watch "URLConnection timeout" New topic
Author

URLConnection timeout

f jimenez
Ranch Hand

Joined: Mar 14, 2007
Posts: 30
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...


if you can't be the sun, be a star...<br />もし たいように なれないたら ほしに なれ。
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42056
    
  64
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.


Ping & DNS - my free Android networking tools app
f jimenez
Ranch Hand

Joined: Mar 14, 2007
Posts: 30
thanks ulf.

how can you do the second option? pls help...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42056
    
  64
Have a look at the java.util.Timer and TimerTask classes.
f jimenez
Ranch Hand

Joined: Mar 14, 2007
Posts: 30
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
Marshal

Joined: Mar 22, 2005
Posts: 42056
    
  64
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

Joined: Mar 14, 2007
Posts: 30
yes, thats exactly what i did... thanks a lot...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: URLConnection timeout