Note that there are some explanatory texts on larger screens.

plurals
  1. POjava.net.socketException:operation time out when running app on real device
    primarykey
    data
    text
    <p>this code works fine on emulator, but on real device it gives </p> <blockquote> <p><em>java.net.SocketException</em>:the operation timed out ive got a php script running on my xampp server.</p> </blockquote> <pre><code>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 the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; } private class FetchSQL extends AsyncTask&lt;String,Void,String&gt; { @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); } } </code></pre> <p>}</p> <p>when i click on button it takes the amt of time ive set in my code, and then fails giving me the error in my textview. please help</p> <p>my php code.</p> <pre><code>&lt;?php // attempt a 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 FROM iwmp_officer"; $result = pg_query($dbh, $sql); if (!$result) { die("Error in SQL query: " . pg_last_error()); } $array = array(); // iterate over 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); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload