Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6055505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:16:19+00:00 2026-05-23T08:16:19+00:00

Right now I’m doing this: while (true) { try { SocketAddress sockaddr = new

  • 0

Right now I’m doing this:

while (true) {
    try {
        SocketAddress sockaddr = new InetSocketAddress(ivDestIP, ivDestPort);
        downloadSock = new Socket();
        downloadSock.connect(sockaddr);
        this.oos = new ObjectOutputStream(downloadSock.getOutputStream());
        this.ois = new ObjectInputStream(downloadSock.getInputStream());
        break;
    } catch (Exception e) {}
}

downloadSock.connect(sockaddr) will generate a ConnectionRefused exception if the remote host is not listening on the socket. I’m running my code in a separate thread, so I’m not worried about blocking. Given this, is my method of retrying appropriate or is there a better way???

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:16:20+00:00Added an answer on May 23, 2026 at 8:16 am

    In this case I usually use a progressively longer sleep period each request.

    It could be that the server is almost up, so you just want to try again in a second. But if that request fails, wait 2 seconds, but if that one fails, wait 4, etc.

    It may be that you want to cap the amount of waiting to 30 seconds or a minute or something like that. It’s probably wise to define the maximum number of tries so you don’t just wait indefinitely.

    Something like this might calculate your next delay in seconds:

    seconds_to_wait = Math.min(60, Math.pow(2, try_num));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I'm doing something like this: RewriteRule ^/?logout(/)?$ logout.php RewriteRule ^/?config(/)?$ config.php I
Right now, I have code that looks something like this: Private Sub ShowReport(ByVal reportName
this is what i have right now Drawing an RSS feed into the php,
Right now when i do something like this: use strict; use warnings; package My::Test;
Right now, I'm using this fashion: window.Foo = { alpha: function() {}, bravo: function(arg)
Right now I clarify this may be a duplicated question from: Right-aligned labels in
right now I'm creating an array and using: render :json => @comments This would
Right now I have to create a new physical file in eclipse android for
Right now, I'm using this to allow a file to be moved to our
Right now I'm using the org.json JSON library. JSONArray data = new JSONArray(); for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.