µWS ("microWS") is a WebSocket and HTTP implementation for clients and servers. Simple, efficient and lightweight.
#include <uWS/uWS.h>
using namespace uWS;
int main() {
Hub h;
std::string response = "Hello!";
h.onMessage([](WebSocket<SERVER> *ws, char *message, size_t length, OpCode opCode) {
ws->send(message, length, opCode);
});
h.onHttpRequest([&](HttpResponse *res, HttpRequest req, char *data, size_t length,
size_t remainingBytes) {
res->end(response.data(), response.length());
});
if (h.listen(3000)) {
h.run();
}
}
Non-profit open source (Zlib) since 2016.