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 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.
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.
Platforms
LWS is available for unix-style platforms like Linux and BSD (including Mac), and also for Windows and
even ESP32 and FreeRTOS.
LWS uses a singlethreaded nonblocking event loop, but it also supports having n of these in n threads,
spreading the connections between them by allocating them to the least busy service thread, providing
scalability to hundreds of thousands of connections in a single instance.
QA
LWS uses SAI CI to test pushes on 269 builds across Linux/gcc, Mac/clang, Windows, ESP32, and OpenBSD, all built with -Wall, -Werror and -Wextra.