I guess the "offset" and "bytesleft" in the curl_ws_meta structure 
(https://curl.se/libcurl/c/curl_ws_meta.html)
provide information about WS message fragments.

"offset" 
When this frame is a continuation of fragment data already delivered, this is 
the offset into the final fragment where this piece belongs.

"bytesleft"
If this is not a complete fragment, the bytesleft field informs about how many 
additional bytes are expected to arrive before this fragment is complete.

I suppose that for the final frame in the WS message the "bytesleft" field 
should be set to zero thus indicating the end of the message.

Thanks,
Dmitry Karpov



-----Original Message-----
From: curl-library <curl-library-boun...@lists.haxx.se> On Behalf Of Paul 
Fotheringham via curl-library
Sent: Tuesday, July 11, 2023 9:35 AM
To: curl-library@lists.haxx.se
Cc: Paul Fotheringham <fotheringham.p...@gmail.com>
Subject: [EXTERNAL] Detecting final WebSocket frame of a fragmented message

Hi,

I've been using libcurl for some months now and recently tried to get WebSocket 
going in CURLOPT_CONNECT_ONLY=2L mode. The problem I'm having is if the server 
sends a message fragmented over multiple frames then I cannot work out how I am 
meant to know when the final frame of the message is received via curl_ws_recv. 
Even if it is not fragmented then I get the whole message but again I guess I 
don't know that the message is finished.

My understanding of WebSocket is that only the final frame (might be the only 
frame) has the FIN bit set in the header but I see no corresponding exposure of 
that in the API and a quick scan of the code seems to suggest it is not being 
passed out in any way. The server is mine too so I may have a bug but at the 
same time I just don't see how I'm meant to detect the final frame.

I understand WebSocket support is still experimental so I'm wondering if I am 
missing something or if this is just not available yet?

Paul
--
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html
-- 
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html

Reply via email to