[Libwebsockets] javascript onMessage

Andy Green andy at warmcat.com
Fri May 22 05:25:07 CEST 2020

On 5/21/20 9:11 PM, pierre laplante wrote:

> When we receive multiple packet in javascript event onmessage, how can we know where it start and where it ends ?

JS only calls your callback when it has a complete "ws message", with a 
beginning and an end, to give you.  The start of the "ws message" is the 
start of the data in JS object it gives you and likewise the end of the 
"ws message" is the end of that.

In lws, by default in ws mode, every time you call lws_write() you are 
sending a new complete js message.  If you send a large but single, 
logical "ws message" over multiple writes, you can send any size of 
message even beyond what a browser is willing to buffer for you in memory.

Use this helper to form the lws_write() flags based on the type of 
message, and whether the part you are sending via lws_write() this time 
is the beginning or the end, or neither.



More information about the Libwebsockets mailing list