cURL / Mailing Lists / curl-library / Single Mail

curl-library

(Secure) Websockets using libcurl

From: Patrick Rathje <PatrickRathje_at_web.de>
Date: Tue, 17 May 2016 17:23:06 +0200

Hey,
I am using libcurl for HTTP(s) already.
Now I would like to support Secure Websockets as well, but could not really find much information how this is done using libcurl.
 
Currently I am using an Easy-Handle to do the initial Websocket Handshake using basic HTTP-Requests, which is working fine and is not a problem.
But after the connection was successfully established, I would like to send websocket messages. (Data already formatted according to the websocket protocol).
As suggested here https://phpandmore.net/2015/02/17/implementing-web-sockets-with-curl/, one may write to the underlying socket directly, which could be used for non-secured websocket connections.
Since I need the connections to be secured and calling write directly seems like a bad idea anyway, I would like to use curl_easy_send.
 
But with curl_easy_send I am running into a problem:
I can not use it unless I add the CURLOPT_CONNECT_ONLY option, but I would need to do the HTTP-Websocket-Handshake by myself.
 
So as a solution, I thought of using two handles which share one tcp-connection:
1. Handle: Creating TCP-Connection (might be secured) and executing the Websocket-Handshake using HTTP. Then detach from connection, but not close it.
2. Handle: Attach to the already existing connection and send / receive Data using curl_easy_send / curl_easy_recv at will.
 
Is this possible with easy handles or if not, using the multi interface?
 
Sincerely yours,
 
Patrick Rathje

-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-05-17