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.

WebSocket custom port name as in JavaScript websockets

From: Johny Bravo via curl-library <>
Date: Thu, 25 May 2023 17:23:58 +0200 (CEST)

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

Received on 2023-05-25