Steve Longhurst wrote:
I came across this issue also. There are a couple of ways to fix it.
>
It’s because the libwebsockets library has a default receive buffer size of 4096 bytes. In WebSocket.cpp, the onSocketCallback method gets called multiple times with LWS_CALLBACK_CLIENT_RECEIVE, in chunks of 4096. This forwards the message data straight to the JavaScript callback via the sendMessageToUIThread method. You could probably write some logic in your websocket.onmessage handler that deals with this, but that’s probably not the best solution.
>
Either you can alter the per protocol receive buffer size, which can be set in the WebSocket::init method, where the _wsProtocols member is setup.
ie. After line 326 in WebSocket.cpp:
>
_wsProtocols[i].rx_buffer_size = 1024 * 64; // 64;
>
Or you can add code to the onSocketCallback method in the LWS_CALLBACK_CLIENT_RECEIVE case, that calls libwebsockets_remaining_packet_payload to determine if any more data is expected. If it is, buffer the data just passed and wait for the next callback. When libwebsockets_remaining_packet_payload returns 0, you can pass all the received data to the JavaScript onmessage handler.
>
I’ve done the second option and have attached my patched WebSocket.cpp and .h files in case anyone is interested. They are patched from the 2.1.4 release version.
>
Hope that helps,
>
Steve
Thanks,Steve, I’ll test your codes,and merge it to our develop branch.