Here's what I've learned in dealing with this particular problem on Android.

SSL connections are costly to set up.  Once set-up, the overhead of SSL 
isn't too bad.  To get around this issue, clients and servers can elect to 
keep a connection open, with the assumption that additional requests may be 
issued again soon (seconds or minutes).  Of course, keeping a connection 
open consumes valuable system resources, especially in high-transaction 
environment.  Clients and servers keep connections open via a "keep alive 
strategy".

Servers are in complete control of how long a socket connection is kept 
alive.  However, a nice server will often tell the client how long it is 
willing to keep a socket open via a non-standard response header, 
"Keep-Alive".  Examples of this header may look like this:

Keep-Alive: timeout=15, max=100
Keep-Alive: timeout=5, max=100
Keep-Alive: 300

The big issue with the "Broken pipe" is that a client doesn't know if the 
other side shut the connection down until it attempts to use the 
connection.  Thus, your client code grabs a connection from the connection 
manager, asks it to do something, only to get an IO Exception/Broken Pipe.

The solution I've found is to give a simple, custom keep-alive strategy as 
follows when you create your DefaultHttpClient:

mHttpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
    @Override
    public long getKeepAliveDuration(HttpResponse response, HttpContext 
context) {
        return 60; // seconds
    }
});

The Apache HttpClient tutorial page gives a better example if you are 
hitting various websites.  I chose to hard-code mine above because my client 
will hit one and only one HTTPS-enabled server which I have configured to 
have a keep-alive of 60 seconds.

Hope this helps!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to