Websocket server does not completely send large binary payload
Created by: psl8r
There seems to be an issue in which large binary payloads > ~400KB are not fully sent by a websocket server and therefore not received by the client.
Steps to reproduce:
- Start a websocket server.
AsyncHttpServer server = new AsyncHttpServer();
server.listen(8000);
server.websocket("/", new AsyncHttpServer.WebSocketRequestCallback() {
@Override
public void onConnected(final WebSocket webSocket, AsyncHttpServerRequest request) {
// TEST: large binary (>400KB) sent from server
InputStream is = getContext().getResources().openRawResource(R.raw.file1561246251481);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int reads;
try {
reads = is.read();
while (reads != -1) {
baos.write(reads);
reads = is.read();
}
byte[] payload = baos.toByteArray();
webSocket.send(payload);
} catch (IOException e) {
e.printStackTrace();
}
}
});
- Connect from a websocket client and wait to receive
AsyncHttpClient.getDefaultInstance().websocket("http://localhost:8000/", "my-protocol", new WebSocketConnectCallback() {
@Override
public void onCompleted(Exception ex, WebSocket webSocket) {
if (ex != null) {
ex.printStackTrace();
return;
}
webSocket.setStringCallback(new StringCallback() {
public void onStringAvailable(String s) {
System.out.println("I got a string: " + s);
}
});
webSocket.setDataCallback(new DataCallback() {
public void onDataAvailable(ByteBufferList byteBufferList) {
System.out.println("I got some bytes!");
// note that this data has been read
byteBufferList.recycle();
}
});
}
});
Expected behavior: Receive full binary payload sent by the server.
Actual behavior: Server does not send all the bytes (stepping through using the debugger) and the client DataCallback never fires.
There is actually no issue when sending large binary payloads from a client to the server, only from the server back to the client do I see an issue.
Thanks.