Permanent HttpURLConnections on Android

I had a problem trying to force the Android application (well, the Service, in the case of its difference) to use persistent HTTP 1.1 connections.

The next cycle (simplified test scenario) works through one TCP session on the JRE desktop, but on the Android device the whole cycle of creating / breaking a socket takes place.

        while (true) {
            URL url;
            try {
                url = new URL("http://10.0.0.125:8080/SRV?");

                URLConnection connection = url.openConnection();

                HttpURLConnection httpConnection = (HttpURLConnection) connection;                  
                int responseCode = httpConnection.getResponseCode();

            } catch (MalformedURLException e) {
            } catch (IOException e) {
            }       
        }

The Oracle JDK describes something called "system properties":

http.keepAlive = default: true

http.maxConnections = default: 5

Is there something similar in the Android runtime that prevents persistent connections from being kept?

+3
source share
2 answers

Android JVM Apache HTTP Components HTTP- ( , java.net): JVM Oracle.

http.keepAlive, Google .

, , HttpComponents. , http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html, http-. 2.11, , HTTP-.

.

+4

HTTP 1.1, . , .

TCP- , , . ": keep-alive" . "Connection: keep-alive". , InputStream, Android... , .

, :

HttpURLConnection con = (HttpURLConnection) url.openConnection();

HttpClient = DefaultHttpClient();

, HttpClient , HttpURLConnection . , , HttpURLConnections, Android DefaultHttpClient.

, Android HTTP 1.1?

+3

All Articles