[Libwebsockets] How to receive message bigger than 4096 bytes on server side?

Andy Green andy at warmcat.com
Thu Nov 5 02:44:50 CET 2015

On 5 November 2015 09:25:22 GMT+08:00, Nemo <377307289 at qq.com> wrote:
>I have create a websocket server with libwebsockets library, and the
>protocol list is like this:
>/* List of supported protocols and callbacks. */ static struct
>libwebsocket_protocols protocols[] = {     { "plain-websocket-protocol"
>/* Custom name. */,       callback_websocket,       sizeof(struct
>websocket_client_real),       0 },     { NULL, NULL, 0, 0 } /*
>Terminator. */ }; 
>When I use "html + javascript + chrumium browser" as client to send
>websocket message bigger than 4096 bytes, the websocket server will
>receive the LWS_CALLBACK_RECEIVE callback more than one time, one
>message is splited to two or more, and the max receive size is 4096.
>How can I receive unlimited size websocket message on server side?

If I understand it you are receiving whatever message you sent.  It's just notifying you as soon as each chunk arrived.

In the browser, in Javascript, it delays notifying you about the message until the whole thing came.  But if you think about it, then you can't get a message bigger than your available memory, for example a long streaming video.

If that's what you want, you need to reassemble the chunks as they get notified into a final buffer yourself.  But it's way more flexible to 'get it as it comes'.


>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org

More information about the Libwebsockets mailing list