11

I have a function in my android code which send data to the web service using KSOAP. I am able to send data to the service, but sometimes I get an exception: "SSLException I/O error during system call, Connection timed out".

After performing a couple of test my observations are:

  • If wifi/mobile data is already ON and I send data to web service I don't get an exception.
  • I only get it when I just turn wifi/mobile data ON and once its connected when I try to send data.

I am clueless on how to get over this exception. If you can please suggest/guide me on how to overcome this exception would be a great help.

Following is the method used to send data to web service which is called in an ASYNC task.

public String incidentDataToServer(JSONObject incidentJSON) {
        // package the request
        SoapObject Request = new SoapObject(INCIDENT_NAMESPACE,
                INCIDENT_METHOD_NAME);
        String incidentData = incidentJSON.toString();
        PropertyInfo pi = new PropertyInfo();
        pi.setName("IncidentJSonString");
        pi.setValue(incidentData);
        pi.setType(String.class);
        Request.addProperty(pi);

        // set the soap serialization envelope, set it to .net and package
        // the entire request and pass to soap envelope.
        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        soapEnvelope.dotNet = true;
        soapEnvelope.setOutputSoapObject(Request);

        HttpTransportSE aht = new HttpTransportSE(URL);
        try {

            aht.call(INCIDENT_SOAP_ACTION, soapEnvelope);
            SoapPrimitive resultString = (SoapPrimitive) soapEnvelope
                    .getResponse();

            resIncident = resultString.toString();

        } catch (Exception e) {
            e.printStackTrace();

        }
        return resIncident;

    }

Exception on wifi

03-27 09:36:45.920: W/System.err(7603): javax.net.ssl.SSLException: Write error: ssl=0x4818f2c8: I/O error during system call, Connection timed out
03-27 09:36:45.960: W/System.err(7603):     at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_write(Native Method)
03-27 09:36:45.960: W/System.err(7603):     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:693)
03-27 09:36:45.960: W/System.err(7603):     at java.io.BufferedOutputStream.flushInternal(BufferedOutputStream.java:185)
03-27 09:36:45.960: W/System.err(7603):     at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:85)
03-27 09:36:45.960: W/System.err(7603):     at libcore.net.http.FixedLengthOutputStream.flush(FixedLengthOutputStream.java:49)
03-27 09:36:45.960: W/System.err(7603):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:188)
03-27 09:36:45.960: W/System.err(7603):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
03-27 09:36:45.960: W/System.err(7603):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)
03-27 09:36:45.960: W/System.err(7603):     at com.dimensions.dimensionsapp.ServerAuthentication.incidentDataToServer(ServerAuthentication.java:121)
03-27 09:36:45.960: W/System.err(7603):     at com.dimensions.dimensionsapp.DataToServer$IncidentDataToServer.doInBackground(DataToServer.java:89)
03-27 09:36:45.960: W/System.err(7603):     at com.dimensions.dimensionsapp.DataToServer$IncidentDataToServer.doInBackground(DataToServer.java:1)
03-27 09:36:45.970: W/System.err(7603):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
03-27 09:36:45.970: W/System.err(7603):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
03-27 09:36:45.970: W/System.err(7603):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-27 09:36:45.970: W/System.err(7603):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
03-27 09:36:45.970: W/System.err(7603):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
03-27 09:36:45.970: W/System.err(7603):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
03-27 09:36:45.970: W/System.err(7603):     at java.lang.Thread.run(Thread.java:856)

Exception on MobileData

03-27 09:47:46.279: W/System.err(3795):     at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_write(Native Method)
03-27 09:47:46.279: W/System.err(3795):     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:693)
03-27 09:47:46.279: W/System.err(3795):     at java.io.BufferedOutputStream.flushInternal(BufferedOutputStream.java:185)
03-27 09:47:46.279: W/System.err(3795):     at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:85)
03-27 09:47:46.299: W/System.err(3795):     at libcore.net.http.FixedLengthOutputStream.flush(FixedLengthOutputStream.java:49)
03-27 09:47:46.299: W/System.err(3795):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:188)
03-27 09:47:46.299: W/System.err(3795):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
03-27 09:47:46.309: W/System.err(3795):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)
03-27 09:47:46.319: W/System.err(3795):     at com.dimensions.dimensionsapp.ServerAuthentication.incidentDataToServer(ServerAuthentication.java:121)
03-27 09:47:46.319: W/System.err(3795):     at com.dimensions.dimensionsapp.DataToServer$IncidentDataToServer.doInBackground(DataToServer.java:89)
03-27 09:47:46.319: W/System.err(3795):     at com.dimensions.dimensionsapp.DataToServer$IncidentDataToServer.doInBackground(DataToServer.java:1)
03-27 09:47:46.319: W/System.err(3795):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
03-27 09:47:46.319: W/System.err(3795):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
03-27 09:47:46.339: W/System.err(3795):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-27 09:47:46.339: W/System.err(3795):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
03-27 09:47:46.339: W/System.err(3795):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
03-27 09:47:46.339: W/System.err(3795):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
03-27 09:47:46.339: W/System.err(3795):     at java.lang.Thread.run(Thread.java:856)

Thank you.

BRDroid
  • 3,920
  • 8
  • 65
  • 143
  • i can see this is an old post, i presume you fixed it? Did you put the block of code in a try/catch statement and before actually sending to the server did you do a check if there is available internet connection? – Gabi Radu Sep 26 '14 at 08:13
  • 1
    Hello user1140656, sorry for the delayed response. Yes the issue is been resolved. Basically I am calling this method from an AsyncTask which is in a separate class(background operations). When ever I have data to be sent to server, I first check if there is internet connection and then call the above function through AsyncTask. – BRDroid Oct 26 '14 at 06:57
  • Yes, checking if there is an internet connection first,then execute the code. – Gabi Radu Oct 26 '14 at 15:28
  • Hello "user1140656", I have been testing the app now and found out that I am still facing the same issue, exception: "SSLException I/O error during system call, Connection timed out",even after checking if there is an internet connection before I send it to server. Any suggestions? – BRDroid Oct 27 '14 at 11:23
  • did you try/catch the block of code and maybe print the System.out? – Gabi Radu Oct 27 '14 at 22:41
  • Yes i do have a try catch block in which i get this exception, – BRDroid Oct 28 '14 at 09:56
  • just to be sure, although i presume you tested this, JSON is valid, URL is correct? No clue what could be wrong. – Gabi Radu Oct 28 '14 at 14:29
  • its a valid JSON and valid URL. I get this exception only the first time i send data after i turn on the wifi or mobile date. from second attempt there is no problem. but if i again turn off internet connection and put it back on and try, i get this exception again. not sure why though. – BRDroid Oct 28 '14 at 14:48
  • Hi Rao, I am getting the same exception what you have faced. Did you get any solution? – SKK Apr 20 '16 at 06:28

2 Answers2

1

This seems similar to a bug in Android which returns disconnected connections: https://code.google.com/p/android/issues/detail?id=65463.

The ksoap2-android library was affected by this, and your SOAP library may be as well. To quote from the issue:

If you use ksoap for android:

ArrayList<HeaderProperty> headerPropertyArrayList = new ArrayList<HeaderProperty>();
headerPropertyArrayList.add(new HeaderProperty("Connection", "close"));

And updating your call with .call(SOAP_ACTION, envelope, headerPropertyArrayList).

0

I know this is older, but just adding to the conversation.

I get this message from time to time in the mountains, when internet goes out, or is too weak, at the exact moment an ssl handshake of an api call out to our servers is made. Internet could be available prior to that call, but midway through, internet drops at the exact inconvenient point in time

What I do to mitigate this, if I absolutely need the call to succeed, is build a retry queue based on the caught exception, and keep trying the call until either it succeeds or you get an acknowledgement of some kind.

For this reason, I am also exploring moving my https network calls over to something MQTT-based to reduce the amount of overhead these handshakes take. Our app is mission critical in places where internet is sketchy though, likely overkill for most.

Matt Fiocca
  • 1,533
  • 13
  • 21