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.
Send data before receiving data using the callback approach for WebSocket requests
- Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [ by author ] [ by messages with attachments ]
From: Darshan Sen via curl-library <curl-library_at_lists.haxx.se>
Date: Mon, 5 Jun 2023 17:08:58 +0530
Hi! I was experimenting with sending WebSocket requests using libcurl.
Since my codebase already uses the callback approach for HTTP requests and
I was just adding support for WebSocket connections, I thought of
continuing using the same write callback for WebSocket connections too.
However, I was trying to connect with a WebSocket server that expects the
client to send data before responding. So I had a question:
When using the callback approach
<https://everything.curl.dev/libcurl/ws/concept#1.-the-callback-approach>,
is it possible to run curl_ws_send() right after the connection is
established, before the write callback function is executed for the first
time?
It isn't documented but I still tried setting CURLOPT_READFUNCTION to a
valid read callback function but that didn't work, so I guess read
callbacks are not expected to work when doing WebSocket requests. Does this
mean that I would need to use the connect-only approach
<https://everything.curl.dev/libcurl/ws/concept#2.-the-connect-only-approach>
for WebSocket connections?
Even if we find a solution for the callback approach, I was wondering if
any of these approaches <https://everything.curl.dev/libcurl/ws/concept> are
recommended over the other?
Thanks!
Date: Mon, 5 Jun 2023 17:08:58 +0530
Hi! I was experimenting with sending WebSocket requests using libcurl.
Since my codebase already uses the callback approach for HTTP requests and
I was just adding support for WebSocket connections, I thought of
continuing using the same write callback for WebSocket connections too.
However, I was trying to connect with a WebSocket server that expects the
client to send data before responding. So I had a question:
When using the callback approach
<https://everything.curl.dev/libcurl/ws/concept#1.-the-callback-approach>,
is it possible to run curl_ws_send() right after the connection is
established, before the write callback function is executed for the first
time?
It isn't documented but I still tried setting CURLOPT_READFUNCTION to a
valid read callback function but that didn't work, so I guess read
callbacks are not expected to work when doing WebSocket requests. Does this
mean that I would need to use the connect-only approach
<https://everything.curl.dev/libcurl/ws/concept#2.-the-connect-only-approach>
for WebSocket connections?
Even if we find a solution for the callback approach, I was wondering if
any of these approaches <https://everything.curl.dev/libcurl/ws/concept> are
recommended over the other?
Thanks!
-- Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-library Etiquette: https://curl.se/mail/etiquette.htmlReceived on 2023-06-05