This is a dependency of our upcoming web-based material debugger. This
CL also includes `tnt/CMakeLists.txt`, which builds a static lib in a
minimal configuration that enables WebSocket support. The entire library
is built from only 4 files:
${PUBLIC_HDR_DIR}/CivetServer.h
${PUBLIC_HDR_DIR}/civetweb.h
${SRC_DIR}/civetweb.c
${SRC_DIR}/CivetServer.cpp
1.4 KiB
1.4 KiB
Civetweb API Reference
mg_websocket_write( conn, opcode, data, data_len );
Parameters
| Parameter | Type | Description |
|---|---|---|
conn |
struct mg_connection * |
Connection on which the data must be written |
opcode |
int |
Opcode |
data |
const char * |
Data to be written to the client |
data_len |
size_t |
Length of the data |
Return Value
| Type | Description |
|---|---|
int |
Number of bytes written or an error code |
Description
The function mg_websocket_write() sends data to a websocket client wrapped in a websocket frame. The function issues calls to mg_lock_connection() and mg_unlock_connection() to ensure that the transmission is not interrupted. Data corruption can otherwise happen if the application is proactively communicating and responding to a request simultaneously.
The function is available only when Civetweb is compiled with the -DUSE_WEBSOCKET option.
The function returns the number of bytes written, 0 when the connection has been closed and -1 if an error occurred.