The WebSocketHandler, built on top of CivetWebSocketHandler, is a websocket handler that handles different types of websocket related events.
More...
#include <websocket_handler.h>
|
| WebSocketHandler (const std::string &name) |
|
bool | handleConnection (CivetServer *server, const Connection *conn) override |
| Callback method for when the client intends to establish a websocket connection, before websocket handshake. More...
|
|
void | handleReadyState (CivetServer *server, Connection *conn) override |
| Callback method for when websocket handshake is successfully completed, and connection is ready for data exchange. More...
|
|
bool | handleData (CivetServer *server, Connection *conn, int bits, char *data, size_t data_len) override |
| Callback method for when a data frame has been received from the client. More...
|
|
bool | handleJsonData (Connection *conn, const std::string &data) |
|
bool | handleBinaryData (Connection *conn, const std::string &data) |
|
void | handleClose (CivetServer *server, const Connection *conn) override |
| Callback method for when the connection is closed. More...
|
|
bool | BroadcastData (const std::string &data, bool skippable=false) |
| Sends the provided data to all the connected clients. More...
|
|
bool | SendData (Connection *conn, const std::string &data, bool skippable=false, int op_code=MG_WEBSOCKET_OPCODE_TEXT) |
| Sends the provided data to a specific connected client. More...
|
|
bool | SendBinaryData (Connection *conn, const std::string &data, bool skippable=false) |
|
void | RegisterMessageHandler (std::string type, MessageHandler handler) |
| Add a new message handler for a message type. More...
|
|
void | RegisterConnectionReadyHandler (ConnectionReadyHandler handler) |
| Add a new handler for new connections. More...
|
|
The WebSocketHandler, built on top of CivetWebSocketHandler, is a websocket handler that handles different types of websocket related events.
◆ Connection
◆ ConnectionReadyHandler
◆ Json
◆ MessageHandler
◆ WebSocketHandler()
apollo::dreamview::WebSocketHandler::WebSocketHandler |
( |
const std::string & |
name | ) |
|
|
inlineexplicit |
◆ BroadcastData()
bool apollo::dreamview::WebSocketHandler::BroadcastData |
( |
const std::string & |
data, |
|
|
bool |
skippable = false |
|
) |
| |
Sends the provided data to all the connected clients.
- Parameters
-
data | The message string to be sent. |
◆ handleBinaryData()
bool apollo::dreamview::WebSocketHandler::handleBinaryData |
( |
Connection * |
conn, |
|
|
const std::string & |
data |
|
) |
| |
◆ handleClose()
void apollo::dreamview::WebSocketHandler::handleClose |
( |
CivetServer * |
server, |
|
|
const Connection * |
conn |
|
) |
| |
|
override |
Callback method for when the connection is closed.
- Parameters
-
server | the calling server |
conn | the connection information |
◆ handleConnection()
bool apollo::dreamview::WebSocketHandler::handleConnection |
( |
CivetServer * |
server, |
|
|
const Connection * |
conn |
|
) |
| |
|
inlineoverride |
Callback method for when the client intends to establish a websocket connection, before websocket handshake.
- Parameters
-
server | the calling server |
conn | the connection information |
- Returns
- true to keep socket open, false to close it
◆ handleData()
bool apollo::dreamview::WebSocketHandler::handleData |
( |
CivetServer * |
server, |
|
|
Connection * |
conn, |
|
|
int |
bits, |
|
|
char * |
data, |
|
|
size_t |
data_len |
|
) |
| |
|
override |
Callback method for when a data frame has been received from the client.
In the websocket protocol, data is transmitted using a sequence of frames, and each frame received invokes this callback method. Since the type of opcode (text, binary, etc) is given in the first frame, this method stores the opcode in a thread_local variable named current_opcode_. And data from each frame is accumulated to data_ until the final fragment is detected. See websocket RFC at http://tools.ietf.org/html/rfc6455, section 5.4 for more protocol and fragmentation details.
- Parameters
-
server | the calling server |
conn | the connection information |
bits | first byte of the websocket frame, see websocket RFC at http://tools.ietf.org/html/rfc6455, section 5.2 |
data | payload, with mask (if any) already applied. |
data_len | length of data |
- Returns
- true to keep socket open, false to close it
◆ handleJsonData()
bool apollo::dreamview::WebSocketHandler::handleJsonData |
( |
Connection * |
conn, |
|
|
const std::string & |
data |
|
) |
| |
◆ handleReadyState()
void apollo::dreamview::WebSocketHandler::handleReadyState |
( |
CivetServer * |
server, |
|
|
Connection * |
conn |
|
) |
| |
|
override |
Callback method for when websocket handshake is successfully completed, and connection is ready for data exchange.
- Parameters
-
server | the calling server |
conn | the connection information |
◆ RegisterConnectionReadyHandler()
Add a new handler for new connections.
- Parameters
-
handler | The function to handle the new connection in ReadyState. |
◆ RegisterMessageHandler()
void apollo::dreamview::WebSocketHandler::RegisterMessageHandler |
( |
std::string |
type, |
|
|
MessageHandler |
handler |
|
) |
| |
|
inline |
Add a new message handler for a message type.
- Parameters
-
type | The name/key to identify the message type. |
handler | The function to handle the received message. |
◆ SendBinaryData()
bool apollo::dreamview::WebSocketHandler::SendBinaryData |
( |
Connection * |
conn, |
|
|
const std::string & |
data, |
|
|
bool |
skippable = false |
|
) |
| |
◆ SendData()
bool apollo::dreamview::WebSocketHandler::SendData |
( |
Connection * |
conn, |
|
|
const std::string & |
data, |
|
|
bool |
skippable = false , |
|
|
int |
op_code = MG_WEBSOCKET_OPCODE_TEXT |
|
) |
| |
Sends the provided data to a specific connected client.
- Parameters
-
conn | The connection to send to. |
data | The message string to be sent. |
skippable | whether the data is allowed to be skipped if some other is being sent to this connection. |
The documentation for this class was generated from the following file: