1 # Civetweb API Reference
3 ### `mg_set_user_connection_data( conn, data );`
7 | Parameter | Type | Description |
9 |**`conn`**|`struct mg_connection *`|connection to add the user data|
10 |**`data`**|`void *`|Pointer to the user data|
18 The function `mg_set_user_connection_data()` can be used to set a user defined
19 data pointer attached to a connection. This value can be read using
20 `mg_get_user_connection_data()`.
21 Any call to `mg_set_user_connection_data()` will overwrite a previously
22 assigned user data pointer.
24 `mg_set_user_connection_data()` requires a non-const
25 `struct mg_connection *` to set the user data pointer. It is save to use the
26 `const struct mg_connection *` passed to a websocket connect handler (with a
27 const cast), since `const` just means you must not use `mg_read()` or
28 `mg_write()` in this context.
30 Alternatively, you can use the `init_connection` callback in
31 `struct mg_callbacks` to set the user data pointer.
32 In this case, typically `init_connection` is used to allocate memory for
33 a user defined `struct`, while `connection_close` is used to free this
39 * [`mg_get_user_connection_data();`](mg_get_user_connection_data.md)
40 * [`struct mg_callbacks`](mg_callbacks.md)
41 * [`mg_set_websocket_handler();`](mg_set_websocket_handler.md)
42 * [`mg_read();`](mg_read.md)
43 * [`mg_write();`](mg_write.md)