Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

retry conncecting to Sockets

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I try to write to a socket, if the destination host is not on line , a Connection Exception will be thrown.
What I want is, when an exception happens, the program keeps retrying to write to socket for a limited time and if in that time the connection was not established , then an Exception indicating the connection failure is
genereated.
 
paul wheaton
Trailboss
Posts: 22078
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would surround your try..catch with a loop that looked like this
<pre>
int tries = 0 ;
boolean done = false;
while ( ! done )
{
tries++ ;
try
{
....
done = true ;
}
catch{}
if ( tries > 5 ) done = true ;
}
</pre>

[This message has been edited by Paul Wheaton (edited January 11, 1999).]
 
Destiny's powerful hand has made the bed of my future. And this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!