2

I have implemented a simple web server on an android phone.

I used an early version of nanohttpd, which seems adequate to the purpose.

Intemittently (approx every 5-10 GET requests) the socket connection time blows out from under 50ms to 3-4 seconds, and not infrequently 10 seconds or more.

The server is not being thrashed. A new thread is created for the server socket listen, and another one for each connection request.

Code Snippet:

 myThread = new Thread( new Runnable()
    {
        public void run()
        {
            try
            {
                while( true )
                    new HTTPSession( myServerSocket.accept());
            }
            catch ( IOException ioe )
            {
                Log.d(IRobotSensors.TAG,"Accept failure: "+ioe.getMessage());
            }
        }
    });

and

    public HTTPSession( Socket s )
    {
        Log.d(IRobotSensors.TAG,"Opening Socket");
        mySocket = s;
        Thread t = new Thread( this );
        t.setDaemon( true );
        t.start();
    }

It's hard to see how this could be overloading the thread manager, and no particular garbage collection or other system activity appears to be happening according to logcat.

The size of the page or image being served does not appear to make a difference, and I've isolated the issue down to the connection time and not anything else the app may be doing AFAICT.

This appears to be an issue with every android device I've tried it on, (which includes tablets and phones of different makes, and different O/S versions) I've tried it on several different local wifi networks, and several different browsers and http clients, and the problem is consistent.

Any ideas?

Robbie Matthews
  • 1,404
  • 14
  • 22

0 Answers0