diff --git a/AndroidAsync/src/com/koushikdutta/async/AsyncNetworkSocket.java b/AndroidAsync/src/com/koushikdutta/async/AsyncNetworkSocket.java index e13860aa..a0d8796a 100644 --- a/AndroidAsync/src/com/koushikdutta/async/AsyncNetworkSocket.java +++ b/AndroidAsync/src/com/koushikdutta/async/AsyncNetworkSocket.java @@ -84,11 +84,16 @@ public void run() { } try { + int before = list.remaining(); - ByteBuffer[] arr = list.getAllArray(); - mChannel.write(arr); - list.addAll(arr); - handleRemaining(list.remaining()); + int remaining = before; + while (remaining > 0) { // busy wait or the socket will timeout with messages > 345kB + ByteBuffer[] arr = list.getAllArray(); + mChannel.write(arr); + list.addAll(arr); + handleRemaining(list.remaining()); + remaining = list.remaining(); + } mServer.onDataSent(before - list.remaining()); } catch (IOException e) {