ws28
C++17 WebSocket server library
Do you use this in production?
Yes.
Should I use this in production?
Maybe.
Is it spec compliant?
Mostly. There's no UTF-8 validation. Everything else should be spec compliant.
How do I use this?
-
Copy the source files into your project, I don't like making libraries.
-
Create a server:
ws28::Server server{uv_default_loop(), SSL_CTX* or nullptr};
Note: if you have a secure server, it'll actually listen for both secure and insecure connections on that same port by sniffing the first byte. This allows you to run insecure websocket servers on port 443 and not deal with the swarm of broken proxies out there.
-
Set up some callbacks
See
src/Server.h
. But basically, you need some or all of these methods fromws28::Server
:SetClientConnectedCallback
,SetClientDisconnectedCallback
,SetClientDataCallback
,SetCheckConnectionCallback
andSetHTTPCallback
. -
Listen
server.Listen(port);
You can also check echo.cpp
for an echo server implementation.
What's the license?
Most files are MIT. The base64 code is BSD, feel free to pull request some MIT licensed code to replace it.
More FAQ
ws28::Client
?
Can I store pointers to Only between ClientConnected and ClientDisconnected callbacks for each client. It is deleted immediately after ClientDisconnected.