What is the maximum size of data that can be passed through a WebSocket?

theapache64 picture theapache64 · Aug 31, 2015 · Viewed 20k times · Source

I am new in Java WebSocket. When I tried to pass a JSON with length greater than 8192, the websocket disconnected immediately. How ever JSON with length <= 8191 works fine.

Is there any MAX SIZE/ LIMIT of data that can be passed through a WebSocket? if yes, what's that size?


I FIXED THE ERROR BY ADDING THESE LINES TO my web.xml

<context-param>
         <param-name>org.apache.tomcat.websocket.textBufferSize</param-name>
         <param-value>32768</param-value>
    </context-param>
    <context-param>
            <param-name>org.apache.tomcat.websocket.binaryBufferSize</param-name>
            <param-value>32768</param-value>
</context-param>

Thanks @Davide Lorenzo MARINO.

Answer

Davide Lorenzo MARINO picture Davide Lorenzo MARINO · Aug 31, 2015

IT is actually a value very big and probably you don't worry about it.

A single frame, by RFC-6455 base framing, has a maximum size limit of 18,446,744,073,709,551,615 bytes (maximum value of a 64-bit unsigned value).

Try only to make it as little as possible to handle your requirements.

Because the problem is generated on the server side (tomcat). Checking the tomcat documentation I see that:

The default buffer size for binary messages is 8192 bytes. This may be changed for a web application by setting the servlet context initialization parameter org.apache.tomcat.websocket.binaryBufferSize to the desired value in bytes.

So you can change it using updating the org.apache.tomcat.websocket.binaryBufferSize parameter in the configuration file of tomcat.

For additional informations please see the tomcat guide here