]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | # Civetweb API Reference |
2 | ||
3 | ### `mg_set_websocket_handler_with_subprotocols( ctx, uri, subprotocols, connect_handler, ready_handler, data_handler, close_handler, cbdata );` | |
4 | ||
5 | ### Parameters | |
6 | ||
7 | | Parameter | Type | Description | | |
8 | | :--- | :--- | :--- | | |
9 | |**`ctx`**|`mg_context *`|The context in which to add the handlers| | |
10 | |**`uri`**|`const char *`|The URI for which the handlers should be activated| | |
11 | |**`subprotocols`**|`struct mg_websocket_subprotocols *`|A list of supported sub-protocols| | |
12 | |**`connect_handler`**|`mg_websocket_connect_handler`|Handler called when a connect is signaled| | |
13 | |**`ready_handler`**|`mg_websocket_ready_handler`|Handler called when the connection is ready| | |
14 | |**`data_handler`**|`mg_websocket_data_handler`|Handler called when data is received| | |
15 | |**`close_handler`**|`mg_websocket_close_handler`|Handler called when the connection closes| | |
16 | |**`cbdata`**|`void *`|User defined data| | |
17 | ||
18 | `int mg_websocket_connect_handler( const struct mg_connection *conn, void *cbdata );` | |
19 | `int mg_websocket_ready_handler( struct mg_connection *conn, void *cbdata );` | |
20 | `int mg_websocket_data_handler( struct mg_connection *conn, int opcode, char * buf, size_t buf_len, void *cbdata );` | |
21 | `int mg_websocket_close_handler( const struct mg_connection *conn, void *cbdata );` | |
22 | ||
23 | ### Return Value | |
24 | ||
25 | *none* | |
26 | ||
27 | ### Description | |
28 | ||
29 | The function `mg_set_websocket_handler_with_subprotocols()` connects callback functions to a websocket URI, just like [`mg_set_websocket_handler();`](mg_set_websocket_handler.md). | |
30 | In addition, it allows to specify websocket sub-protocols. | |
31 | The callback functions are called when a state change is detected on the URI like an incoming connection or data received from a remote peer. | |
32 | ||
33 | ### See Also | |
34 | ||
35 | * [`struct mg_websocket_subprotocols;`](api/mg_websocket_subprotocols.md) | |
36 | * [`mg_set_websocket_handler();`](mg_set_websocket_handler.md) |