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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:26:57+00:00 2026-05-24T07:26:57+00:00

I’m working on a web server for Android and even though I’ve spent days

  • 0

I’m working on a web server for Android and even though I’ve spent days trying to fix it, I’m at my wits’ end with this particular bug. I’m trying to read the request from the browser, and the code works fine most of the time, but something like 5% of the requests fail and it throws random SocketTimeoutExceptions without even reading a single character from the Socket.

I have tested this with different browsers and it happens with all of them, so chances are the problem is on my end. Here’s the relevant code, stripped down as far as possible:

public class ServerThread extends Thread {

private ServerSocket ss = null;
private boolean isRunning;

private ExecutorService threadPool = new ThreadPoolExecutor(2, 12,
          60L, TimeUnit.SECONDS,
          new SynchronousQueue<Runnable>(),
          Executors.defaultThreadFactory(), 
          new ThreadPoolExecutor.CallerRunsPolicy());

public ServerThread() {
}

public synchronized void run() {
    ss = new ServerSocket(8080, 1);
    isRunning = true;

    while (isRunning) {
        Socket clientSocket = null;

        try {
            if (ss != null) {
                clientSocket = ss.accept();
                if (isRunning) {
                    this.threadPool.execute(new HTTPSession(clientSocket));
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
}

And:

public class HTTPSession implements Runnable {

private Socket mSocket = null;

public HTTPSession (Socket s) {
    mSocket = s;
}


public void run() {

    InputStream ips = null;

    try {
        mSocket.setSoTimeout(15000);
        ips = mSocket.getInputStream();
        ips.read();
    }
    catch (Exception e) {
        e.printStackTrace();
        Log.v("HTTPSession", "Socket connected: " + mSocket.isConnected() + ", Socket closed: " + mSocket.isClosed() + ", InputShutdown: " + mSocket.isInputShutdown());
    }
    finally {
            try { ips.close(); } catch (IOException ioe) {  }
            try { mSocket.close(); } catch (IOException ioe) {  }
    }

}
}

So ServerThread accepts the connection, HTTPSession tries to read from the Socket and sometimes it throws the SocketTimeoutException after the 15 seconds are up.

The output from the Log statement in the catch in this case is:
Socket connected: true, Socket closed: false, InputShutDown: false

What gives? Surely 15 seconds is enough of a wait and it seems unlikely that mainstream web browsers just aren’t sending any data, so why can’t I read it?

I would appreciate any input on this problem.

  • 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-24T07:26:58+00:00Added an answer on May 24, 2026 at 7:26 am

    SocketTimeoutException only means one thing: no data was available within the timeout period. So yes maybe your timeout is too short, and yes the browser didn’t send it within the timeout period, or at least it didn’t arrive at the server’s socket receive buffer within the timeout period.

    I would say 15 seconds is a bit aggressive for a server side timeout. 30s to a couple of minutes would be more like it.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.