curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: curl websockets

From: Tomalak Geret'kal via curl-library <curl-library_at_cool.haxx.se>
Date: Wed, 23 Jun 2021 16:38:54 +0100

On 23/06/2021 16:23, Daniel Stenberg via curl-library wrote:
> On Tue, 22 Jun 2021, Weston Schmidt via curl-library wrote:
>
>> I'm interested in feedback or suggestions for what/how to
>> define a good websocket API that complements libcurl.
>
> My very simple idea on how it could be added to the API:
>
> 1. We add another value to set CURLOPT_CONNECT_ONLY to
> (2). If this is used, and the URL is "http(s)://" then
> libcurl could "bootstrap" into a websocket connection.
>
> 2. Once it is completed, we could have the application
> extract the socket (to have something to wait on) and then
> use curl_easy_recv() and curl_easy_send() to receive and
> send websockets data over that connection.
>
> What would this be missing?
>
FWIW, that's pretty much what I do for WSS in cURL, and it
works great.

- HTTP request with the appropriate headers (inc. 101
protocol line)
- Wait for empty line in header receipt hook, then:
- curl_easy_pause and set CURLOPT_FORBID_REUSE,
CURLOPT_CONNECT_ONLY=1
- get FD from CURLINFO_ACTIVESOCKET and start watching it by
adding it to list of "extrafds" for curl_multi_poll
- start doing curl_easy_recv & curl_easy_send as appropriate
- pass any received data into a simple, buffering WebSockets
frame parser
- pass any sent data through a simple, buffering WebSockets
frame composer
- optionally set some timers to periodically sent a Ping
packet & check last receipt time of any Pong packets

Writing it in English is more complicated than the actual code.

I'm not opposed to cURL being able to do this natively, but
for the record it's already pretty easy to build on top of
what's already there.

Cheers



-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.se/mail/etiquette.html
Received on 2021-06-23