Error in android Caused by: libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)

1

I am making an application that sends an image to a server but at the time of sending it I get an error. I have to send it via 3G / 4G and I can not do it ... it's a public ip

Here my code

    URL url = new URL(webAddressToPost);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Connection", "Keep-Alive");

            MultipartEntity entity = new MultipartEntity(
                    HttpMultipartMode.BROWSER_COMPATIBLE);

            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
            byte[] data = bos.toByteArray();
            ByteArrayBody bab = new ByteArrayBody(data, "test.jpg");
            entity.addPart("file", bab);

            entity.addPart("someOtherStringToSend", new StringBody("la cadena aquí"));

            conn.addRequestProperty("Content-length", entity.getContentLength() + "");
            conn.addRequestProperty(entity.getContentType().getName(), entity.getContentType().getValue());

            OutputStream os = conn.getOutputStream();
            entity.writeTo(conn.getOutputStream());

            os.close();
            conn.connect();

and the error that comes out

    W/System.err: java.net.ConnectException: failed to connect to /IP (port 5000): connect failed: ETIMEDOUT (Connection timed out)
    W/System.err:     at libcore.io.IoBridge.connect(IoBridge.java:114)
    W/System.err:     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
    W/System.err:     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
    W/System.err:     at java.net.Socket.connect(Socket.java:843)
    W/System.err:     at com.android.okhttp.internal.Platform.connectSocket(Platform.java:152)
    W/System.err:     at com.android.okhttp.Connection.connect(Connection.java:101)
    W/System.err:     at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:294)
    W/System.err:     at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
    W/System.err:     at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
    W/System.err:     at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
    W/System.err:     at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89)
    W/System.err:     at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:197)
    W/System.err:     at com.example.miguel.server11.MainActivity$ImageUploadTask.doInBackground(MainActivity.java:141)
    W/System.err:     at com.example.miguel.server11.MainActivity$ImageUploadTask.doInBackground(MainActivity.java:106)
    W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:288)
    W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
    W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    W/System.err:     at java.lang.Thread.run(Thread.java:841)
    W/System.err: Caused by: libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
    W/System.err:     at libcore.io.Posix.connect(Native Method)
    W/System.err:     at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
    W/System.err:     at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
    W/System.err:     at libcore.io.IoBridge.connect(IoBridge.java:112)
    W/System.err:   ... 19 more
    
asked by Migue635 12.11.2016 в 04:19
source

1 answer

0

In this case the problem is your connection:

  

java.net.ConnectException: failed to connect to / IP (port 5000):   connect failed: ETIMEDOUT (Connection timed out) Caused by:   libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed   out)

Check if you can make connection on the server and you should also check if you have permission to perform the POST to the server.

    
answered by 12.11.2016 в 16:11