This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

retry conncecting to Sockets  RSS feed

 
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: 22255
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).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!