Javascript websocket message size limits

106 Views Asked by At

We are using the web-socket API provided by JS in the front-end and the ws library to create a web socket server in the back-end (node). Is there a limit for the message size.

1

There are 1 best solutions below

0
On

The web-socket protocol in itself does not impose any message size limit and splits a message into multiple frames. So the web-socket API provided by JS does not have any limitations. But the package used for creating the web socket server the ws library has a property named "maxPayload" which limits the message size. This defaults to 100MiB (1MiB = 1.04MB) and can be increased/decreased.

Proof from the official page of the websocket protocol:

In the WebSocket Protocol, data is transmitted using a sequence of frames. The primary purpose of fragmentation is to allow sending a message that is of unknown size. A fragmented message is conceptually equivalent to a single larger message whose payload is equal to the concatenation of the payloads of the fragments in order. If the data to be sent is large, the client encapsulate the data in a series of frames

Proof from the official page of the websocket server

maxPayload {Number} The maximum allowed message size in bytes. Defaults to 100 MiB (104857600 bytes).