1# Civetweb API Reference
2
3### `mg_set_websocket_handler( ctx, uri, 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|**`connect_handler`**|`mg_websocket_connect_handler`|Handler called when a connect is signalled|
12|**`ready_handler`**|`mg_websocket_ready_handler`|Handler called when the connection is ready|
13|**`data_handler`**|`mg_websocket_data_handler`|Handler called when data is received|
14|**`close_handler`**|`mg_websocket_close_handler`|Handler called when the connection closes|
15|**`cbdata`**|`void *`|User defined data|
16
17`int mg_websocket_connect_handler( const struct mg_connection *conn, void *cbdata );`
18`int mg_websocket_ready_handler( struct mg_connection *conn, void *cbdata );`
19`int mg_websocket_data_handler( struct mg_connection *conn, int opcode, char * buf, size_t buf_len, void *cbdata );`
20`int mg_websocket_close_handler( const struct mg_connection *conn,  void *cbdata );`
21
22### Return Value
23
24*none*
25
26### Description
27
28The function `mg_set_websocket_handler()` connects callback functions to a websocket URI. 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.
29
30### See Also
31