I have tried websocket API, but I cannot get it working and receive message.

If I use the ws in JavaScript, I have:




var socket = new WebSocket( "wss://some_url", "example");




However, I dont know, how to set "example" port in libCURL API. I have tried






curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, "example");




but I still dont receive messages.

I got stuck at res = curl_ws_recv(curl, buffer, sizeof(buffer), &nread, &
meta); where res always returns CURLE_AGAIN, no matter how long I wait.




libCURL verbose log gives me this:




*   Trying <IP>:443...
* Connected to some_url (IP) port 443 (#0)
* schannel: disabled automatic use of client certificate

> GET / HTTP/1.1
Host: some_url
Accept: */*
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: xxxxxx==

< HTTP/1.1 101 Switching Protocols
< Server: nginx/1.20.2
< Date: Thu, 25 May 2023 15:04:32 GMT
< Connection: upgrade
< Upgrade: WebSocket
< Sec-WebSocket-Accept: xxxx=
* Received 101, switch to WebSocket; mask 5ae99ef1
<
* Connection #0 to some_url left intact
-- 
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html

Reply via email to