Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: ServerSocket.accept() randomly freezes
    primarykey
    data
    text
    <p>I have a <code>WebView</code> that is fed from a background thread via a <code>ServerSocket</code> on localhost. This works very well, but sometimes the background thread randomly stops accepting requests ("Web page not available"). After some time, it works again without any changes, that is, without restarting the thread or the socket or calling <code>accept()</code> again.</p> <p><strong>EDIT 2:</strong> Further investigation showed that <code>WebView</code> seems to have a (separate?) timeout value for localhost connections that is so small that sometimes the server thread doesn't get a chance to handle the request. As a workaround, I can reload the page when <code>WebClient.onReceivedError</code> is invoked, which eventually loads the page. Anyone having the same problem?</p> <p>When I open the debugger, I can see that the server thread is still running properly and is waiting (blocked) in the <code>ServerSocket.accept()</code> method (or, more precisely, in <code>OSNetworkSystem.accept(...)</code>). However, <code>accept()</code> doesn't seem to receive the incoming request.</p> <p>There is is nothing special in my code:</p> <pre><code>ServerSocket serverSocket = new ServerSocket(port); serverSocket.setSoTimeout(0); while (!shutdown) { Socket socket = null; try { socket = serverSocket.accept(); // Parse request and create response } catch (Exception e) { // ... } finally { // ... close socket } } </code></pre> <p>I use the same code on Windows/Mac and have never experienced any such problems.</p> <p>This seems to me like a bug in Android, perhaps related to power management optimizations. Any clues?</p> <p><strong>EDIT:</strong> The problem does not occur on Android 2.x, only on Android 3.1 (Samsung Galaxy Tab 10.1).</p>
    singulars
    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.
 

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