Overview
Libwebsockets (LWS) is a flexible, lightweight pure C library for implementing modern network protocols easily with a tiny footprint, using a nonblocking event loop. It has been developed continuously since 2010 and is used in tens of millions of devices and by thousands of developers around the world.
LWS is Free Software using the MIT license.
Getting started
git clone https://libwebsockets.org/repo/libwebsockets
LWS roles
LWS Core code handles generic socket lifecycle, tls, vhosts, service threads, timers, unix domain sockets, SOCKS5 etc.
"Roles" are wire protocol implementations on top of that, isolated via an ops struct:
| Role | Client | Server |
| http/1.x | ⭘ | ⭘ |
| http/2 | ⭘ | ⭘ |
| http/3 | ⭘ | ⭘ |
| websockets | ⭘ | ⭘ |
| ws-over-h2 | ⭘ | ⭘ |
| ws-over-h3 | ⭘ | ⭘ |
| raw tcp / udp / file | ⭘ | ⭘ |
| MQTT | ⭘ | ⨯ |
LWS supports optional TLS for client or server (including client certs) on any role.
New roles can be added cleanly to lws.
TLS (SSL) support
| TLS | Yes | No |
| OpenSSL | h1,h2,wss,DTLS | h3 |
| LibreSSL | h1,h2,h3,wss,DTLS | |
| AWS-LC | h1,h2,h3,wss,DTLS |
| BoringSSL | h1,h2,h3,wss,DTLS |
| wolfSSL | h1,h2,h3,wss,DTLS |
| mbedTLS | h1,h2,h3,wss,DTLS |
| GnuTLS | h1,h2,h3,wss,DTLS |
| Schannel | h1,h2,h3,wss,DTLS |
| BearSSL | h1,h2,wss | h3,DTLS |
All support client + server, http/1, http/2 and wss-over-h2.
BearSSL: no DTLS or QUIC/h3. OpenSSL: incompatible QUIC/h3. Others: h3, wss-over-h3, DTLS.
LWS Protocols
User code interfaces to LWS roles by providing a "protocol", including callback for events the code is interested in customizing.
Event loop libraries
LWS defaults to using poll(), however
glib,
libuv,
libevent and
libev event libraries are all supported.
LWS may both provide an internal loop, or participate cleanly in an external, "foreign" loop. New event libs
can be added cleanly to lws.
LWS user code does not have to be customized depending on the event loop in use. For example LWS provides a generic
high-resolution timer for each connection to arrange for delayed callbacks, hiding the details of the exact
implementation depending on the chosen event loop.