0
votes

I'm trying to do a get request from my app to my computer using the format my_ip:8888/msg/my_message When I open the connection it works but the execution never gets past the execute(request) part. It times out (1 minute to) before it does the get request. The request url is correct because I've tried directly on my pc browser. My android manifest has the internet permission. Here's the code

    private static JSONObject sendPetition(HttpUriRequest request) throws Exception{
        AndroidHttpClient client;

        HttpResponse response;
        JSONObject responseJSON;

        client = AndroidHttpClient.newInstance("IPM-HttpClient/UNAVAILABLE");
        response=  client.execute(request);
        responseJSON = new JSONObject(EntityUtils.toString(response.getEntity()));
        client.close();
        return responseJSON;
    }

edit 1:

Seems like I haven't given enough info. sorry: this is the log

11-29 12:10:21.503 5546-5546/com.example.alvarofeal.aplicacioncliente I/View﹕ Touch up dispatch to android.widget.Button{41f3ede0 VFED..C. ...P.... 311,754-407,826 #7f080002 app:id/button}, event = MotionEvent { action=ACTION_UP, id[0]=0, x[0]=59.31427, y[0]=32.06659, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=2125112, downTime=2124997, deviceId=4, source=0x1002 }

11-29 12:10:21.504 5546-5546/com.example.alvarofeal.aplicacioncliente V/Provider/Settings﹕ from settings cache , name = sound_effects_enabled , value = 0

11-29 12:10:21.506 5546-5546/com.example.alvarofeal.aplicacioncliente D/dalvikvm﹕ create interp thread : stack size=128KB

11-29 12:10:21.506 5546-5546/com.example.alvarofeal.aplicacioncliente D/dalvikvm﹕ create new thread

11-29 12:10:21.507 5546-5546/com.example.alvarofeal.aplicacioncliente D/dalvikvm﹕ new thread created

11-29 12:10:21.507 5546-5546/com.example.alvarofeal.aplicacioncliente D/dalvikvm﹕ update thread list

11-29 12:10:21.507 5546-5669/com.example.alvarofeal.aplicacioncliente D/dalvikvm﹕ threadid=12: interp stack at 0x6126a000

11-29 12:10:21.507 5546-5669/com.example.alvarofeal.aplicacioncliente D/dalvikvm﹕ threadid=12: created from interp

11-29 12:10:21.507 5546-5546/com.example.alvarofeal.aplicacioncliente D/dalvikvm﹕ start new thread

11-29 12:10:21.507 5546-5669/com.example.alvarofeal.aplicacioncliente D/dalvikvm﹕ threadid=12: notify debugger

11-29 12:10:21.507 5546-5669/com.example.alvarofeal.aplicacioncliente D/dalvikvm﹕ threadid=12 (AsyncTask #1): calling run()

11-29 12:10:21.509 5546-5669/com.example.alvarofeal.aplicacioncliente I/System.out﹕ httpget:http:// 192.168.0.8:8888/msg/play/eABHFSQKCdU

11-29 12:10:21.512 5546-5669/com.example.alvarofeal.aplicacioncliente I/System.out﹕ http:// 192.168.0.8:8888/msg/play/eABHFSQKCdU

11-29 12:10:21.519 5546-5669/com.example.alvarofeal.aplicacioncliente D/dalvikvm﹕ create interp thread : stack size=128KB

11-29 12:10:21.519 5546-5669/com.example.alvarofeal.aplicacioncliente D/dalvikvm﹕ create new thread

11-29 12:10:21.519 5546-5669/com.example.alvarofeal.aplicacioncliente D/dalvikvm﹕ new thread created

11-29 12:10:21.519 5546-5669/com.example.alvarofeal.aplicacioncliente D/dalvikvm﹕ update thread list

11-29 12:10:21.519 5546-5670/com.example.alvarofeal.aplicacioncliente D/dalvikvm﹕ threadid=13: interp stack at 0x6138a000

11-29 12:10:21.519 5546-5670/com.example.alvarofeal.aplicacioncliente D/dalvikvm﹕ threadid=13: created from interp

11-29 12:10:21.519 5546-5669/com.example.alvarofeal.aplicacioncliente D/dalvikvm﹕ start new thread

11-29 12:10:21.520 5546-5670/com.example.alvarofeal.aplicacioncliente D/dalvikvm﹕ threadid=13: notify debugger

11-29 12:10:21.520 5546-5670/com.example.alvarofeal.aplicacioncliente D/dalvikvm﹕ threadid=13 ([email protected]@41fae950): calling run()

11-29 12:10:21.533 5546-5669/com.example.alvarofeal.aplicacioncliente I/System.out﹕ [socket][0] connection /192.168.0.8:8888;LocalPort=34838(60000)

11-29 12:10:21.533 5546-5669/com.example.alvarofeal.aplicacioncliente I/System.out﹕ [CDS]connect[/192.168.0.8:8888] tm:60

11-29 12:10:21.534 5546-5669/com.example.alvarofeal.aplicacioncliente D/Posix﹕ [Posix_connect Debug]Process com.example.alvarofeal.aplicacioncliente :8888

After that it just throws a connectiontimeout exception:

edit3:

11-29 12:27:19.988 6207-6277/com.example.alvarofeal.aplicacioncliente W/System.err﹕ org.apache.http.conn.ConnectTimeoutException: Connect to /192.168.0.8:8888 timed out

11-29 12:27:19.990 6207-6277/com.example.alvarofeal.aplicacioncliente W/System.err﹕ at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:121)

11-29 12:27:19.991 6207-6277/com.example.alvarofeal.aplicacioncliente W/System.err﹕ at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)

11-29 12:27:19.992 6207-6277/com.example.alvarofeal.aplicacioncliente W/System.err﹕ at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)

11-29 12:27:19.992 6207-6277/com.example.alvarofeal.aplicacioncliente W/System.err﹕ at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)

11-29 12:27:19.993 6207-6277/com.example.alvarofeal.aplicacioncliente W/System.err﹕ at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:365)

11-29 12:27:19.994 6207-6277/com.example.alvarofeal.aplicacioncliente W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:587)

11-29 12:27:19.995 6207-6277/com.example.alvarofeal.aplicacioncliente W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:511)

11-29 12:27:19.996 6207-6277/com.example.alvarofeal.aplicacioncliente W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:489)

11-29 12:27:19.996 6207-6277/com.example.alvarofeal.aplicacioncliente W/System.err﹕ at android.net.http.AndroidHttpClient.execute(AndroidHttpClient.java:260)

11-29 12:27:19.997 6207-6277/com.example.alvarofeal.aplicacioncliente W/System.err﹕ at com.example.alvarofeal.model.Model.sendPetition(Model.java:29)

11-29 12:27:19.998 6207-6277/com.example.alvarofeal.aplicacioncliente W/System.err﹕ at com.example.alvarofeal.model.Model.playVideo(Model.java:38)

11-29 12:27:19.999 6207-6277/com.example.alvarofeal.aplicacioncliente W/System.err﹕ at com.example.alvarofeal.aplicacioncliente.VideoList$Videos.doInBackground(VideoList.java:170)

11-29 12:27:20.000 6207-6277/com.example.alvarofeal.aplicacioncliente W/System.err﹕ at com.example.alvarofeal.aplicacioncliente.VideoList$Videos.doInBackground(VideoList.java:165)

11-29 12:27:20.003 6207-6277/com.example.alvarofeal.aplicacioncliente W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:288)

11-29 12:27:20.005 6207-6277/com.example.alvarofeal.aplicacioncliente W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)

11-29 12:27:20.007 6207-6277/com.example.alvarofeal.aplicacioncliente W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)

11-29 12:27:20.009 6207-6277/com.example.alvarofeal.aplicacioncliente W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)

11-29 12:27:20.012 6207-6277/com.example.alvarofeal.aplicacioncliente W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)

11-29 12:27:20.013 6207-6277/com.example.alvarofeal.aplicacioncliente W/System.err﹕ at java.lang.Thread.run(Thread.java:841)

Setup: I'm using my android device and I'm trying to comunicate to my computer (port 8888). They are both in the same network.

1
Can you post you AndroidHttpClient class? - romtsn
@rom4ek it's imported android.net.http.AndroidHttpClient; - Álvaro
using the format. Please tell exactly the url you use. Your code is not very usefull to debug this problem as the actions involved are hidden. If there is a timeout you will have exceptions or errors mentioned in the logcat. Please post. - greenapps
When I open the connection it works. What do you mean by that? What works? - greenapps
@greenapps Added the log so you can see the url and waht's going on in the app. - Álvaro

1 Answers

0
votes

I think you should setting the timeout to your request, like this:

   private static JSONObject sendPetition(HttpUriRequest request) throws Exception{
        AndroidHttpClient client;
        int timeout = 5000

        HttpResponse response;
        JSONObject responseJSON;

        client = AndroidHttpClient.newInstance("IPM-HttpClient/UNAVAILABLE");

        HttpParams httpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
        HttpConnectionParams.setSoTimeout(httpParams, timeout);

        request.setParams(httpParams);

        response = client.execute(request);
        responseJSON = new JSONObject(EntityUtils.toString(response.getEntity()));
        client.close();
        return responseJSON;
    }