I think there should be WS_OPEN callback, called when WebSocket has been 
successfully opened, which would allow to send data right after opening.
That's how I did it in my C++ WebSocket implementation layer over libcurl.

And I think most of WS clients provide such "on open" notifications.

Thanks,
Dmitry Karpov

-----Original Message-----
From: curl-library <curl-library-boun...@lists.haxx.se> On Behalf Of Daniel 
Stenberg via curl-library
Sent: Tuesday, June 6, 2023 11:17 PM
To: Darshan Sen via curl-library <curl-library@lists.haxx.se>
Cc: Daniel Stenberg <dan...@haxx.se>
Subject: [EXTERNAL] Re: Send data before receiving data using the callback 
approach for WebSocket requests

On Mon, 5 Jun 2023, Darshan Sen via curl-library wrote:

> Actually, I would still need this to work with the callback approach 
> because my application is required to work in a push-based mechanism, 
> so that it can allow users to attach callbacks to listen for received 
> data instead of a pull-based model where users would need to 
> explicitly call my APIs to pull in the received data. To be clear, I'm 
> basically creating a libcurl-based Node.js C++ addon 
> <https://nodejs.org/api/addons.html> for the WebSocket JavaScript Web 
> API <https://developer.mozilla.org/en-US/docs/Web/API/WebSocket> where 
> users should be able to attach callback handlers to process the 
> received data and explicitly call my APIs to send data.

Right now, the callback approach only sends incoming data to the write callback 
so there is no way to first send data or to use the read callback.

I'm open for discussing how we can improve this so maybe we can come up with a 
way for this that can be made to work in a future?

-- 

  / daniel.haxx.se
  | Commercial curl support up to 24x7 is available!
  | Private help, bug fixes, support, ports, new features
  | https://curl.se/support.html
--
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