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

  • Home
  • SEARCH
  • 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 6635661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:04:57+00:00 2026-05-25T23:04:57+00:00

I have an Android app that sends commands to a robot via HTTP. (The

  • 0

I have an Android app that sends commands to a robot via HTTP. (The robot server is written in Python using the BaseHttpServer class.) I’m setting up my connection in the app correctly as far as I can tell, but most requests fail to return and if they do there is a very long delay. Here is the initialization code:

    private void setupHttpStuff() {
      HttpParams params = new BasicHttpParams();
      ConnManagerParams.setMaxTotalConnections(params, 10);
      HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

      SchemeRegistry schemeRegistry = new SchemeRegistry();
      schemeRegistry.register(
            new Scheme("http", PlainSocketFactory.getSocketFactory(), 1504));

      ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
      this.HttpClient = new DefaultHttpClient(cm, params);
    }

The GET request takes place in an AsyncTask and the code looks like:

    HttpContext localContext = new BasicHttpContext();
    HttpGet httpGet = new HttpGet(url);
    mClient.execute(httpGet, localContext);

Where mClient is a variable shared from the Activity.

By using Log.d messages I’ve determined that the first two requests work fine but then all subsequent requests (in separate AsyncTasks) hang and never return from execute. I’ve also tried to manually create a Socket and send a HttpRequest:

    Socket socket = new Socket("192.168.1.45", 1504);
    HttpParams params = new BasicHttpParams(); 
    DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
    conn.bind(socket, params);
    HttpRequest request = new BasicHttpRequest("GET", "/");
    conn.sendRequestHeader(request);
    HttpResponse response = conn.receiveResponseHeader(); // Hangs here
    conn.receiveResponseEntity(response);
    socket.close();

But this hangs on the conn.receiveResponseHeader() line and the server never sees the request.

The Python server works fine with requests from a browser, just not with my Android app. I’ve tried this single-threaded as well in the main UI but the same effect occurs.

EDIT

Here is the Python code that causes the problems:

class MyHand(BaseHTTPServer.BaseHTTPRequestHandler):

    def do_GET(self):

        qv = parse_qs(get_qs(urlparse(self.path)))

        if("method" not in qv):
            self.send_nack()

        elif(qv["method"][0] == "drive"):
            createbot.Drive(int(qv["velocity"][0]), int(qv["radius"][0]))
            self.send_ack()

        else:
            self.send_nack()

    def send_ack(self, content_type='text/html'):

        self.send_response(200)
        self.send_header('Content-type', content_type)
        self.end_headers()

    def send_nack(self):

        self.send_response(500)
        self.send_header('Content-type', 'text/html')
        self.end_headers()
  • 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-25T23:04:58+00:00Added an answer on May 25, 2026 at 11:04 pm

    This may be related to keep-alive. Android sends Connection: Keep-Alive and Python sends back a Connection: close. I’ve looked at the HTTP headers that are being sent from Firefox and HttpClient and there is no difference (other than Firefox sending some additional Accept headers). Somehow Android is expecting the Python server to send something other than HTTP/1.1 200 OK\nContent-type: text/html and therefore keeping the socket open. I ended up writing my own basic HTTP server and client.

    Python code:

    class SingleTCPHandler(SocketServer.BaseRequestHandler):
    
        def handle(self):
            data = self.request.recv(1024)
            parts = data.rsplit(" ")
            if (parts[0] != "GET"):
                self.request.close()
                return
    
            url = parts[1].split("?")[1]
            qv = parse_qs(url)
            ...
    

    Android:

        Socket socket = null;
        PrintWriter output = null;
    
        try {
            socket = new Socket(this.ipAddress, this.portNo);
            output = new PrintWriter(new BufferedWriter
                    (new OutputStreamWriter(socket.getOutputStream())), true);
            output.println("GET " + url);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (socket != null)
                    socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
    
            if (output != null)
                output.close();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my current app for Android I have an HTTP client that sends a
I have a class that extends android.app.Dialog, the layout is done in an xml
I have created an app that sends some data via bluetooth and my app
I have an Android app that fetches data from the web service using ksoap2,
I have a client who needs an Android App that can recognize spoken commands.
I've created this android app that sends onTouchEvents points to a web server, and
Im writing a client/server app for android that sends a username and password to
I have an Android project that branched into three different applications, app-1 , app-2
I have a simple client-server app on android. the android service communicates with the
I am developing an Android app that connects to the Facebook Open Graph via

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.