Skip to content Skip to sidebar Skip to footer

Socketexception( Connection Timed Out ) Is Thrown When I Run My Android App On A Real Device

My android app needs to perform Http requests through HttpClient. i've tested on the emulator and it works fine. but when i do it on a real device with WIFI activated, sometimes A

Solution 1:

When ever I get this its when I get no data connection. Also check you have the right permissions cause that can do it to.

Solution 2:

Try using another method of sending HTTP request:

url = "http://<your URL>";
URLurlObj=newURL(url);
Log.d("DEBUG", "url=" + url);
URLConnectionlu= urlObj.openConnection();

//optional - send parametersStringdata= URLEncoder.encode("param", "UTF-8") + "=" + URLEncoder.encode(value, "UTF-8"); //optional - send parameters// Send data
lu.setDoOutput(true);
OutputStreamWriterwr=newOutputStreamWriter(lu.getOutputStream());
wr.write(data);
wr.flush();
//end of "optional"// Get the responseBufferedReaderrd=newBufferedReader(newInputStreamReader(lu.getInputStream()));
Stringline="", res = "";
while ((line = rd.readLine()) != null) {
    res += line;
}

wr.flush();
wr.close();
Log.d("DEBUG", "res=" + res);

Post a Comment for "Socketexception( Connection Timed Out ) Is Thrown When I Run My Android App On A Real Device"