Note that there are some explanatory texts on larger screens.

plurals
  1. PONIO non-blocking socketChannel. Data was not received on the other side
    text
    copied!<p>I have a very strange behaviour during writing to a NIO socket. In my mobile client I'm using a NIO socketChannel which is configured as follows:</p> <pre><code>InetSocketAddress address = new InetSocketAddress(host, port); socketChannel = SocketChannel.open(); socketChannel.socket().connect(address, 10000); socketChannel.configureBlocking(false); </code></pre> <p>then periodically (every 60 seconds) I write some data to this socketChannel (the code here is a little bit simplified):</p> <pre><code>ByteBuffer readBuffer = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE); readBuffer.clear(); int numRead = -1; numRead = socketChannel.read(readBuffer); Log.write("Read " + numRead + " bytes" ); if(numRead &gt; 0) { processServerResponse(readBuffer); } else if(numRead &lt; 0) { // ... re-connect etc. } // ... byte[] msg = getNextMessage(); ByteBuffer buffer = ByteBuffer.wrap(msg); int numOfBytes = 0; while(buffer.hasRemaining()) { numOfBytes += socketChannel.write(buffer); } Log.write("Written " + numOfBytes + " bytes of " + msg.length ); </code></pre> <p>And it works. But... Sometimes (very infrequently, may 1 or 2 times per day) my server don't receive data. My client log looks like:</p> <pre><code>Written 10 bytes of 10 Written 20 bytes of 20 Written 30 bytes of 30 Written 40 bytes of 40 Written 50 bytes of 50 </code></pre> <p>and so on. But on the server side it looks like:</p> <pre><code>Received 10 bytes of 10 Received 50 bytes of 50 </code></pre> <p>20, 30 and 40 bytes data records were not received, despite of fact that on the client side it looks like all data was sent without any exceptions! (In reality the server log is a little bit better than this simplified version. So I can see which data was sent (my sent records contain timestamps etc)) </p> <p>Such gaps can be small (2-3 minutes) which is not very bad, but sometimes they can be very big (1-2 hours = 60-120 cycles) and it is really a problem for my customers.</p> <p>I really have no idea what can be wrong. The data seems to be sent by client, but it never arrives on the server side. I've checked it also with a proxy. </p> <p>I would be very grateful for any ideas and tips.</p> <p>P.S. Maybe it plays some role: the client code runs on an Android mobile device which is moving (it is in a car). The internet connection is established through GPRS.</p>
 

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