1

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 + chromium 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, the max receive size is 4096.

How can I receive unlimited size websocket message on server side?

Dr.Nemo
  • 1,451
  • 2
  • 11
  • 15

2 Answers2

0

The lws_protocols struct now has a rx_buffer_size member so you should be able to configure the 4096 size using this. See the api doc for details https://libwebsockets.org/libwebsockets-api-doc.html

Gerard Condon
  • 761
  • 1
  • 7
  • 22
0

This answer will address this question:

How can I receive unlimited size websocket message on server side?

It's relatively simple, actually. And you don't need to change your rx_buffer_size like it was suggested before.

Check out the function size_t lws_remaining_packet_payload(struct lws *wsi) documented in here: https://libwebsockets.org/libwebsockets-api-doc.html

You can use this function in your LWS_CALLBACK_RECEIVE callback handler to determine if the data your callback was given finishes a complete WebSocket "packet" (aka, message). If this function returns nonzero, then there is more data coming for this packet in a future callback. So your application should buffer this data until lws_remaining_packet_payload(wsi) returns 0. At that point, you have read a complete message and can handle the complete message as appropriate.

josh798
  • 78
  • 8