webfirmframework for Java Experts
WebSocket connection is getting closed while sending large data from HTML5 WebSocket client to server.
A WebSocket server may have data size limit for sending and receiving data it doesn't matter whether it is text or binary. For instance, tomcat (which follows JSR 356) has limitation for sending & receiving data, binaryBufferSize and textBufferSize represent it. The default limit is 8192 bytes.
If we are sending data above its limit from any websocket client (eg: HTML5 websocket client) and the server is unable to deliver it the server may close the websocket connection. If you are receiving data in the server as a single chuck, the server will be unable to deliver it.
The solution to avoid this issue is to receive data as partial in OnMessage, This example shows how to receive data in partial.
The same case is applicable for sending data from websocket server
to client. If the size of data is above its allowed limit (8192
bytes) we have to send it as partial.
sendBinary(part, last);
takes partial bytes and also checks whether it is the last part. Checkout this code to get a clear idea about sending partial bytes.