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.

Re: WebSocket custom port name as in JavaScript websockets

From: Henrik Holst via curl-library <>
Date: Thu, 25 May 2023 20:45:07 +0200

AFAIK you are talking about the Sec-WebSocket-Protocol header and that is a
normal HTTP header so you can add it using the normal http header functions.

So if this had been C and not js then:

struct curl_slist *slist = curl_slist_append (NULL,
"Sec-WebSocket-Protocol: protocol");
curl_easy_setopt (curl, CURLOPT_HTTPHEADER, slist);

to set it to the value "protocol".


Den tors 25 maj 2023 kl 20:03 skrev Johny Bravo via curl-library <>:

> No, I have wss server written in libwebsockets that runs on my server.
> Part of libwebsocket init is to set "port name"
> const char * name => Protocol name that must match the one given in the
> client Javascript new WebSocket(url, 'protocol') name
> But I am not sure, how to read from my server using libCURL if I setup
> protocol name on the server. If I leave name empty, it does not work either
> plus JS version does not work either.
> ---------- Původní e-mail ----------
> Od: Dan Fandrich via curl-library <>
> Komu:
> Kopie: Dan Fandrich <>
> Datum: 25. 5. 2023 19:25:16
> Předmět: Re: WebSocket custom port name as in JavaScript websockets
> On Thu, May 25, 2023 at 05:23:58PM +0200, Johny Bravo via curl-library
> wrote:
> > 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
> It sounds like you're trying to use libcurl to talk to a browser. My
> understanding is that this will never work, because WebSockets is for
> peer-to-server communication and not peer-to-peer and libcurl provides
> only
> a client WebSockets implementation, like a browser does.
> Dan
> --
> Unsubscribe:
> Etiquette:
> --
> Unsubscribe:
> Etiquette:

Received on 2023-05-25