1 # Civetweb API Reference
3 ### `mg_lock_connection( conn );`
7 | Parameter | Type | Description |
8 |**`conn`**|`struct mg_connection *`|The connection to retrieve a lock|
16 The function `mg_lock_connection()` is specifically for websocket connections to lock connection. Using this function in combination with [`mg_unlock_connection();`](mg_unlock_connection.md) is necessary around [`mg_write()`](mg_write.md) and [`mg_printf()`](mg_printf.md) calls if the code has server-initiated communication, as well as with communication in direct response to a message.
20 * [`mg_lock_context();`](mg_lock_context.md)
21 * [`mg_printf();`](mg_printf.md)
22 * [`mg_unlock_connection();`](mg_unlock_connection.md)
23 * [`mg_unlock_context();`](mg_unlock_context.md)
24 * [`mg_websocket_client_write();`](mg_websocket_client_write.md)
25 * [`mg_websocket_write();`](mg_websocket_write.md)
26 * [`mg_write();`](mg_write.md)