mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-08-23 02:17:15 +00:00
Fix README WebSocket example to match actual API (Fix #2493)
The quick preview used a nonexistent httplib::ws::Message type with .is_text()/.data. The actual API, as shown in README-websocket.md, uses a plain std::string with ws.read(msg).
This commit is contained in:
@@ -1490,11 +1490,9 @@ See [README-sse.md](README-sse.md) for more details.
|
|||||||
httplib::Server svr;
|
httplib::Server svr;
|
||||||
|
|
||||||
svr.WebSocket("/ws", [](const httplib::Request &req, httplib::ws::WebSocket &ws) {
|
svr.WebSocket("/ws", [](const httplib::Request &req, httplib::ws::WebSocket &ws) {
|
||||||
httplib::ws::Message msg;
|
std::string msg;
|
||||||
while (ws.read(msg)) {
|
while (ws.read(msg)) {
|
||||||
if (msg.is_text()) {
|
ws.send("Echo: " + msg);
|
||||||
ws.send("Echo: " + msg.data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user