android - java.net.socketException:operation time out when running app on real device -


this code works fine on emulator, on real device gives

java.net.socketexception:the operation timed out ive got php script running on xampp server.

package com.example.new1;    import java.io.bufferedreader;  import java.io.inputstreamreader;  import java.net.httpurlconnection;  import java.net.url;   import android.os.asynctask;  import android.os.bundle;  import android.app.activity;  import android.view.menu;  import android.view.view;  import android.widget.textview;    public class mainactivity extends activity {   textview tx;   stringbuilder stringbuilder; @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     tx= (textview)findviewbyid(r.id.text); }  public void func(view view) {     //tx.settext("working fine till here.");      new fetchsql().execute(); }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.activity_main, menu);     return true; } private class fetchsql  extends asynctask<string,void,string>  {         @override     protected string doinbackground(string... arg0) {             url url = null;             bufferedreader reader = null;              string myurl = "http://10.22.35.4:80/conc2.php";         try         { url =new url(myurl);           httpurlconnection connection = (httpurlconnection) url.openconnection();           connection.setrequestmethod("get");           connection.setreadtimeout(15*10000);           connection.connect();           reader = new bufferedreader(new inputstreamreader(connection.getinputstream()));           stringbuilder = new stringbuilder();           string line = null;           while ((line = reader.readline()) != null)           {             stringbuilder.append(line + "\n");            }         // todo auto-generated method stub         return stringbuilder.tostring();         }         catch(final exception e)         {              return e.tostring();           }      }       protected void onpostexecute(final string result)     {         tx.settext(result);     }   } 

}

when click on button takes amt of time ive set in code, , fails giving me error in textview. please help

my php code.

<?php // attempt connection  $dbh = pg_connect("host=10.22.35.11 dbname=iwmp_dev2 user=postgres ");    if (!$dbh) {  die("error in connection: " . pg_last_error());  }          // execute query  //$sql = $_post['plat'];  $sql = "select officer_name iwmp_officer";   $result = pg_query($dbh, $sql);  if (!$result) {  die("error in sql query: " . pg_last_error());  }         $array = array(); // iterate on result set // print each row while ($row = pg_fetch_assoc($result, null)) {   $i++;   $array = implode('+',$row);  echo $array;    }       // free memory     pg_free_result($result);              // close connection      pg_close($dbh);        ?>        

java.net.socketexception exception comes when port trying reach not closed or not available. takes amount of time have specified searching port , gets out.

firstly, try call service on mobile web browser check whether available or not. if not show means device not connected network on file resides.

it may possible firewall not allowing ping port. when doing emulator works since on same pc in case of real device connects via local network , time firewall not allow. solution: unblock request on firewall or try closing firewall.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -