⚠️ This documentation corresponds to the latest development branch of axmol. It might diverge from the official releases.
|
Axmol Engine 3.0.0-dff292a
|
WebSocket implementation using yasio. More...
#include <WebSocket.h>
Classes | |
| struct | Data |
| Data structure for message view. More... | |
| class | Delegate |
| The delegate class is used to process websocket events. More... | |
Public Types | |
| enum class | ErrorCode { } |
| ErrorCode enum used to represent the error in the websocket. More... | |
| enum class | State { } |
| State enum used to represent the Websocket state. More... | |
| enum class | ErrorCode { } |
| ErrorCode enum used to represent the error in the websocket. More... | |
| enum class | State { } |
| State enum used to represent the Websocket state. More... | |
Public Member Functions | |
| WebSocket () | |
| Constructor of WebSocket. | |
| virtual | ~WebSocket () |
| Destructor of WebSocket. | |
| bool | open (Delegate *delegate, std::string_view url, std::string_view caFilePath="", std::string_view protocols="") |
| The initialized method for websocket. | |
| void | send (std::string_view message) |
| Sends string data to websocket server. | |
| void | send (const void *data, unsigned int len) |
| Sends binary data to websocket server. | |
| void | close (uint16_t code=1000, std::string_view reason="Normal close") |
| Closes the connection to server synchronously. | |
| void | closeAsync (uint16_t code=1000, std::string_view reason="Normal close") |
| Closes the connection to server asynchronously. | |
| State | getReadyState () const |
| Gets current state of connection. | |
| std::string_view | getUrl () const |
| Gets the URL of websocket connection. | |
| std::string_view | getProtocol () const |
| Gets the protocol selected by websocket server. | |
| WebSocket () | |
| Constructor of WebSocket. | |
| virtual | ~WebSocket () |
| Destructor of WebSocket. | |
| bool | open (Delegate *delegate, std::string_view url, std::string_view caFilePath="", std::string_view protocols="") |
| The initialized method for websocket. | |
| void | send (std::string_view message) |
| Sends string data to websocket server. | |
| void | send (const void *data, unsigned int len) |
| Sends binary data to websocket server. | |
| void | close (uint16_t code=1000, std::string_view reason="Normal close") |
| Closes the connection to server synchronously. | |
| void | closeAsync (uint16_t code=1000, std::string_view reason="Normal close") |
| Closes the connection to server asynchronously. | |
| State | getReadyState () const |
| Gets current state of connection. | |
| std::string_view | getUrl () const |
| Gets the URL of websocket connection. | |
| std::string_view | getProtocol () const |
| Gets the protocol selected by websocket server. | |
| void | setHeaders (const std::vector< std::string > &headers) |
| Set custom-defined headers. | |
| const std::vector< std::string > & | getHeaders () const |
| Get custom headers. | |
WebSocket implementation using yasio.
Please note that all public methods of WebSocket have to be invoked on Axmol Thread.
|
strong |
ErrorCode enum used to represent the error in the websocket.
| Enumerator | |
|---|---|
| CONNECTION_FAILURE | < value 0 |
| NO_SEC_ACCEPT | < value 1 |
| CONNECTION_FAILURE | < value 0 |
| NO_SEC_ACCEPT | < value 1 |
|
strong |
State enum used to represent the Websocket state.
| Enumerator | |
|---|---|
| OPEN | < value 0 |
| CLOSING | < value 1 |
| CLOSED | < value 2 |
| OPEN | < value 0 |
| CLOSING | < value 1 |
| CLOSED | < value 2 |
|
strong |
ErrorCode enum used to represent the error in the websocket.
| Enumerator | |
|---|---|
| CONNECTION_FAILURE | < value 0 |
| NO_SEC_ACCEPT | < value 1 |
| CONNECTION_FAILURE | < value 0 |
| NO_SEC_ACCEPT | < value 1 |
|
strong |
State enum used to represent the Websocket state.
| Enumerator | |
|---|---|
| OPEN | < value 0 |
| CLOSING | < value 1 |
| CLOSED | < value 2 |
| OPEN | < value 0 |
| CLOSING | < value 1 |
| CLOSED | < value 2 |
| bool open | ( | Delegate * | delegate, |
| std::string_view | url, | ||
| std::string_view | caFilePath = "", | ||
| std::string_view | protocols = "" ) |
The initialized method for websocket.
It needs to be invoked right after websocket instance is allocated.
| delegate | The delegate which want to receive event from websocket. |
| url | The URL of websocket server. |
| protocols | The websocket protocols that agree with websocket server |
| caFilePath | The ca file path for wss connection |
| protocols | Comma-separated list of sub-protocols that agree with websocket server |
| void send | ( | std::string_view | message | ) |
Sends string data to websocket server.
| message | string data. @lua sendstring |
| void send | ( | const void * | data, |
| unsigned int | len ) |
Sends binary data to websocket server.
| data | binary string data. |
| len | the size of binary string data. @lua sendstring |
| void close | ( | uint16_t | code = 1000, |
| std::string_view | reason = "Normal close" ) |
Closes the connection to server synchronously.
| void closeAsync | ( | uint16_t | code = 1000, |
| std::string_view | reason = "Normal close" ) |
Closes the connection to server asynchronously.
|
inline |
Gets current state of connection.
| bool open | ( | Delegate * | delegate, |
| std::string_view | url, | ||
| std::string_view | caFilePath = "", | ||
| std::string_view | protocols = "" ) |
The initialized method for websocket.
It needs to be invoked right after websocket instance is allocated.
| delegate | The delegate which want to receive event from websocket. |
| url | The URL of websocket server. |
| caFilePath | The ca file path for wss connection |
| protocols | Comma-separated list of sub-protocols that agree with websocket server |
| void send | ( | std::string_view | message | ) |
Sends string data to websocket server.
| message | string data. @lua sendstring |
| void send | ( | const void * | data, |
| unsigned int | len ) |
Sends binary data to websocket server.
| data | binary data. |
| len | the size of binary string data. @lua sendstring |
| void close | ( | uint16_t | code = 1000, |
| std::string_view | reason = "Normal close" ) |
Closes the connection to server synchronously.
| void closeAsync | ( | uint16_t | code = 1000, |
| std::string_view | reason = "Normal close" ) |
Closes the connection to server asynchronously.
|
inline |
Gets current state of connection.
|
inline |
Set custom-defined headers.
| headers | The string vector of custom-defined headers. |
|
inline |
Get custom headers.