WebSocket is wrapper of the libwebsockets-protocol, let the develop could call the websocket easily.
More...
|
| WebSocket () |
| Constructor of WebSocket.
|
|
virtual | ~WebSocket () |
| Destructor of WebSocket.
|
|
bool | init (const Delegate &delegate, const std::string &url, const std::vector< std::string > *protocols=nullptr, const std::string &caFilePath="") |
| The initialized method for websocket. More...
|
|
void | send (const std::string &message) |
| Sends string data to websocket server. More...
|
|
var | send ( var message) |
| Sends string data to websocket server. More...
|
|
local | sendstring ( local message) |
| Sends string data to websocket server. More...
|
|
void | send (const unsigned char *binaryMsg, unsigned int len) |
| Sends binary data to websocket server. More...
|
|
var | send ( var binaryMsg, var len) |
| Sends binary data to websocket server. More...
|
|
local | sendstring ( local binaryMsg, local len) |
| Sends binary data to websocket server. More...
|
|
void | close () |
| Closes the connection to server synchronously. More...
|
|
void | closeAsync () |
| Closes the connection to server asynchronously. More...
|
|
State | getReadyState () |
| Gets current state of connection. More...
|
|
const std::string & | getUrl () const |
| Gets the URL of websocket connection.
|
|
var | getUrl () |
| Gets the URL of websocket connection.
|
|
local | getUrl () |
| Gets the URL of websocket connection.
|
|
const std::string & | getProtocol () const |
| Gets the protocol selected by websocket server.
|
|
var | getProtocol () |
| Gets the protocol selected by websocket server.
|
|
local | getProtocol () |
| Gets the protocol selected by websocket server.
|
|
WebSocket is wrapper of the libwebsockets-protocol, let the develop could call the websocket easily.
Please note that all public methods of WebSocket have to be invoked on Cocos Thread.
static void closeAllConnections |
( |
| ) |
|
|
static |
Close all connections and wait for all websocket threads to exit.
- Note
- This method has to be invoked on Cocos Thread
var closeAllConnections |
( |
| ) |
|
|
static |
Close all connections and wait for all websocket threads to exit.
- Note
- This method has to be invoked on Cocos Thread
local closeAllConnections |
( |
| ) |
|
|
static |
Close all connections and wait for all websocket threads to exit.
- Note
- This method has to be invoked on Cocos Thread
bool init |
( |
const Delegate & |
delegate, |
|
|
const std::string & |
url, |
|
|
const std::vector< std::string > * |
protocols = nullptr , |
|
|
const std::string & |
caFilePath = "" |
|
) |
| |
The initialized method for websocket.
It needs to be invoked right after websocket instance is allocated.
- Parameters
-
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 |
- Returns
- true: Success, false: Failure.
var init |
( |
var |
delegate, |
|
|
var |
url, |
|
|
var |
protocols = nullptr , |
|
|
var |
caFilePath = "" |
|
) |
| |
The initialized method for websocket.
It needs to be invoked right after websocket instance is allocated.
- Parameters
-
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 |
- Returns
- true: Success, false: Failure.
void send |
( |
const std::string & |
message | ) |
|
Sends string data to websocket server.
- Parameters
-
Sends string data to websocket server.
- Parameters
-
local sendstring |
( |
local |
message | ) |
|
Sends string data to websocket server.
- Parameters
-
void send |
( |
const unsigned char * |
binaryMsg, |
|
|
unsigned int |
len |
|
) |
| |
Sends binary data to websocket server.
- Parameters
-
binaryMsg | binary string data. |
len | the size of binary string data. |
var send |
( |
var |
binaryMsg, |
|
|
var |
len |
|
) |
| |
Sends binary data to websocket server.
- Parameters
-
binaryMsg | binary string data. |
len | the size of binary string data. |
local sendstring |
( |
local |
binaryMsg, |
|
|
local |
len |
|
) |
| |
Sends binary data to websocket server.
- Parameters
-
binaryMsg | binary string data. |
len | the size of binary string data. |
Closes the connection to server synchronously.
- Note
- It's a synchronous method, it will not return until websocket thread exits.
Closes the connection to server synchronously.
- Note
- It's a synchronous method, it will not return until websocket thread exits.
Closes the connection to server synchronously.
- Note
- It's a synchronous method, it will not return until websocket thread exits.
Closes the connection to server asynchronously.
- Note
- It's an asynchronous method, it just notifies websocket thread to exit and returns directly, If using 'closeAsync' to close websocket connection, be careful of not using destructed variables in the callback of 'onClose'.
Closes the connection to server asynchronously.
- Note
- It's an asynchronous method, it just notifies websocket thread to exit and returns directly, If using 'closeAsync' to close websocket connection, be careful of not using destructed variables in the callback of 'onClose'.
Closes the connection to server asynchronously.
- Note
- It's an asynchronous method, it just notifies websocket thread to exit and returns directly, If using 'closeAsync' to close websocket connection, be careful of not using destructed variables in the callback of 'onClose'.
The documentation for this class was generated from the following file: