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 8963619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:23:50+00:00 2026-06-15T16:23:50+00:00

I have an interesting issue. I have an application where inside of it, I’m

  • 0

I have an interesting issue.

I have an application where inside of it, I’m trying to account for the condition where the phone is connected to a router, but that router is not connected to the internet.

I’ve tried multiple methods of establishing the connection, but NONE of the timeouts account for this condition.

I’ve tried:

HttpParams httpParameters = new BasicHttpParams();
int timeoutSocket = 1000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutSocket);

I’ve also tried:

HttpURLConnection huc = (HttpURLConnection)serverAddress.openConnection();

huc.setDoOutput(true);
huc.setRequestMethod("PUT"); // For amazon
//huc.setRequestMethod("POST"); // For regular server.
huc.setRequestProperty("Content-Type", "text/plain");
huc.setRequestProperty("Content-Length", String.valueOf(bytes));
huc.setFixedLengthStreamingMode(bytes);
huc.setConnectTimeout(1000); // Establishing connection timeout
huc.setReadTimeout(1000);

But in BOTH cases, when I execute/ get the output stream, it takes about 20 seconds to receive an UnknownHostException error.

I would like that reduced to a maximum of 5 seconds before reaching that conclusion.

Is there any way to do this?

Cheers

  • 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-06-15T16:23:50+00:00Added an answer on June 15, 2026 at 4:23 pm

    Through lots of searching and through the help of this link I’ve found a solid solution that seams to be working so far.

    My understanding of the conclusion is that when I use methods like:

    DataOutputStream wr = new DataOutputStream(huc.getOutputStream());
    

    or

    InputStream is = ucon.getInputStream();
    BufferedInputStream bis = new BufferedInputStream(is);
    

    (uploading or downloading)

    There is a lot of things happening under the hood. Including a DNS lookup call. With no-connectivity, but while connected to a router, this is taking about 20 seconds to finally reach a UnknownHostException.

    However, if I add this line of code first before the above code is executed:

    InetAddress iAddr = InetAddress.getByName("myserverName.com");
    

    Then it will give me the proper SocketTimeOutException and responds exactly how I would hope/expect it to. The above line of code apparently caches the DNS Lookup, and the timeouts work as expected.

    Also, something to note: that once the failure is cached, executing the code above will take as long to fail as the other previous code. (Can’t tell you exactly what will trigger this) But if you connect to the internet again, and then enter the connected but no connectivity state again, the earlier success will be cached and the timeouts will again work properly.

    This wasn’t particularly easy to find or figure out, so I hope this helps somebody.

    Cheers,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran across an interesting issue today. We have an application that utilizes Zend
I have an interesting issue with HTTPS ports not being handled properly. It is
Someone please help. I have an interesting issue. I am trying to implement an
I have ran into an interesting issue while trying to create a more usable
I am facing an interesting issue: Currently I have a button that says Print,
Ok I have an interesting issue on an iPad application I am developing. When
We have an application that has some interesting memory usage issues. When it first
I ran into an interesting issue today. I have canvas elements that I am
I have an interesting problem that I've been trying to simplify. I have a
I have a rather interesting issue with SVG animation. I am animating along a

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.