Error in sending data to web server

0

I have a big problem, I made an application that obtains data of latitude and longitude and every minute this data is sent to a server (it is not local), when running the application only 1 device is the one that registers the data, the second, third on does not have record in database, when checking the logs I get the following:

[sony-d2502-YT9110FLP4]: W/System.err: java.net.ConnectException: failed to connect to www...club/162.213.255.72 (port 443): connect failed: ETIMEDOUT (Connection timed out)
[sony-d2502-YT9110FLP4]: W/System.err:     at libcore.io.IoBridge.connect(IoBridge.java:128)
[sony-d2502-YT9110FLP4]: W/System.err:     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
[sony-d2502-YT9110FLP4]: W/System.err:     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
[sony-d2502-YT9110FLP4]: W/System.err:     at java.net.Socket.connect(Socket.java:887)
[sony-d2502-YT9110FLP4]: W/System.err:     at com.android.okhttp.internal.Platform.connectSocket(Platform.java:174)
[sony-d2502-YT9110FLP4]: W/System.err:     at com.android.okhttp.Connection.connect(Connection.java:152)
[sony-d2502-YT9110FLP4]: W/System.err:     at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:276)
[sony-d2502-YT9110FLP4]: W/System.err:     at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
[sony-d2502-YT9110FLP4]: W/System.err:     at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:382)
[sony-d2502-YT9110FLP4]: W/System.err:     at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
[sony-d2502-YT9110FLP4]: W/System.err:     at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:217)
[sony-d2502-YT9110FLP4]: W/System.err:     at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
[sony-d2502-YT9110FLP4]: W/System.err:     at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:25)
[sony-d2502-YT9110FLP4]: W/System.err:     at com.example.israel.bsubicaestudiante.Insercion.insertarPosicion(Insercion.java:147)
[sony-d2502-YT9110FLP4]: W/System.err:     at com.example.israel.bsubicaestudiante.Servicio$4.run(Servicio.java:183)
[sony-d2502-YT9110FLP4]: W/System.err:     at java.lang.Thread.run(Thread.java:818)
[sony-d2502-YT9110FLP4]: W/System.err: Caused by: android.system.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
[sony-d2502-YT9110FLP4]: W/System.err:     at libcore.io.Posix.connect(Native Method)
[sony-d2502-YT9110FLP4]: W/System.err:     at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:111)
[sony-d2502-YT9110FLP4]: W/System.err:     at libcore.io.IoBridge.connectErrno(IoBridge.java:141)
[sony-d2502-YT9110FLP4]: W/System.err:     at libcore.io.IoBridge.connect(IoBridge.java:126)
[sony-d2502-YT9110FLP4]: W/System.err:  ... 15 more

The insertion code is as follows (I put Log to locate the error):

HttpsURLConnection conection;
        //HttpURLConnection conection;
        try {
            Log.d(LOG,"TRY");
            URL url = new URL(dir_web);
            conection = (HttpsURLConnection) url.openConnection();

            conection.setRequestMethod("POST");
            conection.setSSLSocketFactory(CustomSSLSocketFactory.getSSLSocketFactory(context));
            conection.setDoOutput(true);
            conection.setRequestProperty("Content-Type", "application/json");

            Log.d(LOG, "conexion");
            Map obj = new LinkedHashMap();
            obj.put("imei", imei);
            obj.put("direccion", dir);
            obj.put("hora", tiempo.getHour());
            obj.put("fecha", tiempo.getDate());
            obj.put("origen", ori);

            StringWriter out = new StringWriter();
            JSONValue.writeJSONString(obj, out);
            Log.d(LOG, out.toString());

            DataOutputStream wr = new DataOutputStream(conection.getOutputStream());
            wr.writeBytes(out.toString());
            wr.flush();
            wr.close();

            int res = conection.getResponseCode();
            Log.d(LOG,"=>repuesta:"+res);
            if (res == HttpsURLConnection.HTTP_OK) {
                Log.d("Respuesta", " Insertart posicion Bien");
            } else {
                Log.d("Error", "Insertart posicion Error");
            }

        } catch (MalformedURLException e) {
            Log.i(LOG,"MalformedURLException");
            insertarError(imei, "insertarPosicion" + e.toString(), context);
        } catch (ProtocolException e) {
            Log.i(LOG,"ProtocolException");
            insertarError(imei, "insertarPosicion" + e.toString(), context);
        } catch (IOException e) {
            Log.i(LOG,"IOException");
            e.printStackTrace();
            insertarError(imei, "insertarPosicion" + e.toString(), context);
        } catch (CertificateException e) {
            Log.i(LOG,"CertificateException");
            insertarError(imei, "insertarPosicion" + e.toString(), context);
        } catch (GeneralSecurityException e) {
            Log.i(LOG,"GeneralSecurityException");
            insertarError(imei, "insertarPosicion" + e.toString(), context);
        }

It seems that when inserting a record at the same time one of the devices is relegated, could you help me in the solution? thanks.

    
asked by Isra 14.03.2018 в 17:18
source

0 answers