documented changes

This commit is contained in:
The-EDev 2022-05-28 09:53:48 +03:00
parent 65fcdea968
commit 16358b60ec
No known key found for this signature in database
GPG Key ID: 51C45DC0C413DCD9
1 changed files with 5 additions and 1 deletions

View File

@ -5,12 +5,16 @@ To create a websocket in Crow, you need a websocket route.<br>
A websocket route differs from a normal route quite a bit. It uses A slightly altered `CROW_WEBSOCKET_ROUTE(app, "/url")` macro, which is then followed by a series of methods (with handlers inside) for each event. These are (sorted by order of execution):
- `#!cpp onaccept([&](const crow::request&){handler code goes here})` (This handler has to return `bool`)
- `#!cpp onaccept([&](const crow::request& req, void** userdata){handler code goes here})`
- `#!cpp onopen([&](crow::websocket::connection& conn){handler code goes here})`
- `#!cpp onmessage([&](crow::websocket::connection& conn, const std::string message, bool is_binary){handler code goes here})`
- `#!cpp onerror([&](crow::websocket::connection& conn){handler code goes here})`
- `#!cpp onclose([&](crow::websocket::connection& conn, const std::string reason){handler code goes here})`
!!! note
`onaccept` must return a boolean. In case `false` is returned, the connection is shut down, deleted, and no further communication is done.
!!! Warning
By default, Crow allows Clients to send unmasked websocket messages, which is useful for debugging but goes against the protocol specification. Production Crow applications should enforce the protocol by adding `#!cpp #define CROW_ENFORCE_WS_SPEC` to their source code.