Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid from time to time refuses connection when connecting to server socket
    primarykey
    data
    text
    <p>So I have an application that communicates android devices in the same local network with each other. They periodically speak to each other by connecting to by establishing connection to serversocket, exchaning data and closing connection (every minute).</p> <p>For some reason, it works well for first couple of attempts and then they start to return connectoin refused each time. Anybody can tell me what could be the reason?</p> <p>My code is very simple:</p> <pre><code>server = new ServerSocket(0); while(true) { Socket clientSocket = server.accept(); Log.d(TAG, "Incoming connection"); handleClient(clientSocket); } </code></pre> <p>And when connecting:</p> <pre><code> Socket s = new Socket(si.getInet4Addresses()[0], si.getPort()); doStuff(s) </code></pre> <p>I have the following permissions:</p> <pre><code> &lt;manifest&gt; .... &lt;uses-permission android:name="android.permission.INTERNET"/&gt; &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/&gt; &lt;uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/&gt; &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt; &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/&gt; &lt;uses-permission android:name="android.permission.WAKE_LOCK"/&gt; &lt;uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/&gt; &lt;uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/&gt; &lt;application &lt;activity&gt; ... &lt;intent-filter&gt; ... &lt;/intent-filter&gt; &lt;/activity&gt; &lt;service .. /&gt; &lt;receiver &gt; .... &lt;/receiver&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>Oh and should I mention it all happens in a service.</p>
    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