Note that there are some explanatory texts on larger screens.

plurals
  1. POgetInputStream in Async Task
    primarykey
    data
    text
    <p>I have an Activity which calls an Async task to accept socket connections through a predefined InetAddress.</p> <p>The Async task calls another Async task to listen for messages in. but it hangs on the get input stream</p> <p>I have been racking my brain for hours and cannot work out why it is hanging...any help please.</p> <pre><code>public void startSocketListener(InetAddress groupOwnerAddress) { // TODO Auto-generated method stub AcceptClientThread accept; try { accept = new AcceptClientThread(); accept.execute(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public class AcceptClientThread extends AsyncTask&lt;Void, String, String&gt;{ public AcceptClientThread() throws IOException{ } @Override protected void onCancelled() { // TODO Auto-generated method stub try { serverSocket.close(); } catch (IOException e) { // TODO Auto-generated catch block Log.e("CONNECTION ERR", "Could not close serverSocket " + e.toString()); } super.onCancelled(); } @Override protected String doInBackground(Void... params) { try { serverSocket = new ServerSocket(port); } catch (IOException e) { Log.e("CONNECTION ERR","Could not listen on port: " + port); onCancelled(); } while (listening){ try { Log.i("CONNECTION", "AWAITING CONNECTION TO CLIENT"); Socket newSocket = serverSocket.accept(); Log.i("CONNECTION", "CONNECTED TO CLIENT"); ListenerThread lThread = new ListenerThread(newSocket); lThread.execute("Do it"); Log.i("CONNECTION", "ACCEPTED CLIENT"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); onProgressUpdate("could not accept client"); } } Log.i("CONNECTION", "close socket"); try { serverSocket.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return "table connected"; } @Override protected void onProgressUpdate(String... values) { super.onProgressUpdate(values); // received data is first element in the String //Toast.makeText(KitchenActivity.this, values[0], Toast.LENGTH_SHORT).show(); } } public class ListenerThread extends AsyncTask&lt;String, Order, Void&gt; { private Socket socket; ObjectInputStream ois; public ListenerThread(Socket socket){ this.socket = socket; try { ois = new ObjectInputStream(this.socket.getInputStream()); //hangs here } catch (StreamCorruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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