DEV Community

Cover image for WebSocket and curl
Mathieu Kerjouan
Mathieu Kerjouan

Posted on

WebSocket and curl

In a previous publication I was talking about the lake of WebSocket support from curl, but it seems I was not using the latest version at this time. I retried that with the 8.20.0 release after reading "websocket in curl" post by Stefan Eissing. It's not "perfect" but it works like netcat.

The first step is to fetch/install the latest curl version for your system, at this time, the 8.20.0 release

$ wget https://github.com/stunnel/static-curl/releases/download/8.20.0/curl-linux-x86_64-glibc-8.20.0.tar.xz
$ tar xvf curl-linux-x86_64-glibc-8.20.0.tar.xz
$ ./curl --version
curl 8.20.0 (x86_64-pc-linux-gnu) libcurl/8.20.0 OpenSSL/4.0.0 zlib/1.3.2 brotli/1.2.0 zstd/1.5.7 c-ares/1.34.6 libidn2/2.3.8 libpsl/0.21.5 libssh2/1.11.1 nghttp2/1.69.0 ngtcp2/1.22.1 nghttp3/1.15.0
Release-Date: 2026-04-29
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns mqtt mqtts pop3 pop3s rtsp scp sftp smtp smtps telnet tftp ws wss
Features: alt-svc asyn-rr AsynchDNS brotli ECH HSTS HTTP2 HTTP3 HTTPS-proxy HTTPSRR IDN IPv6 Largefile libz PSL SSL SSLS-EXPORT threadsafe TLS-SRP UnixSockets zstd
Enter fullscreen mode Exit fullscreen mode

Then we can use it against a WebSocket server, let try it with buckaroo project.

$ ./curl -T. -kv --no-progress-meter ws://127.0.0.1:8081/ws
*   Trying 127.0.0.1:8081...
* Established connection to 127.0.0.1 (127.0.0.1 port 8081) from 127.0.0.1 port 43194 
* using HTTP/1.x
> GET /ws HTTP/1.1
> Host: 127.0.0.1:8081
> User-Agent: curl/8.20.0
> Accept: */*
> Upgrade: websocket
> Sec-WebSocket-Version: 13
> Sec-WebSocket-Key: Y7nHv/MjumObou+aYHQJTg==
> Connection: Upgrade
> 
* Request completely sent off
< HTTP/1.1 101 Switching Protocols
< connection: Upgrade
< date: Wed, 27 May 2026 13:01:47 GMT
< sec-websocket-accept: nYSHGW+IDHwj5BJCocg6kA6Jsz8=
< server: Cowboy
< upgrade: websocket
< 
* Received 101, Switching to WebSocket
* [WS] Received 101, switch to WebSocket
{ [5 bytes data]
test
heytest
hello!
hello!
* upload completely sent off: 24 bytes
Enter fullscreen mode Exit fullscreen mode

It... Works! Curl is still one of the greatest open-source software available on this planet. Having the power to use a WebSocket like netcat with curl is really really cool.

Have fun!


Cover Image by Sebastian Schuster on Unsplash

Top comments (0)