Search code examples
cnetwork-programmingwebsocketlibwebsockets

libwebsocket send payload limitation


I'm having libwebsocket client to send binary data. I've saved my binary data into a buffer [i.e. buf] and writing to socket.

n = libwebsocket_write(wsi,
       &buf[LWS_SEND_BUFFER_PRE_PADDING], l, opts | LWS_WRITE_BINARY);

My problem is socket is able to write 22392 bytes only [As I've received n= 22392]. when my l >=22392 bytes it is noticed as partial write. This value varies for various architectures.

Question:

  • Is there any limitation of data size in libwebsocket?

  • Any way to extend the buffer payload value?


Solution

  • I got the answer for my question. That is the payload value which prevented my data. Adjust the payload value according to the data size.

    struct libwebsocket_protocols {
       const char * name;
       callback_function * callback;
       size_t per_session_data_size;
       size_t rx_buffer_size;
       unsigned int id;
       struct libwebsocket_context * owning_server;
       int protocol_index;
    };
    

    rx_buffer_size
    you should set this to the size of the biggest legal frame that you support.

    After setting rx_buffer_size to 65536 I'm able to write data completely.

    Here's links helped to me
    https://libwebsockets.org/trac/libwebsockets/ticket/40
    https://libwebsockets.org/libwebsockets-api-doc.html