cocos2d-x  2.2.3-gd2.113-rev1ec524e
Loading...
Searching...
No Matches
WebSocket Class Reference

#include <WebSocket.h>

Classes

struct  Data
 Data structure for message. More...
 
class  Delegate
 The delegate class to process websocket events. More...
 

Public Types

enum  ErrorCode { kErrorTimeout = 0 , kErrorConnectionFailure , kErrorUnknown }
 Errors in websocket. More...
 
enum  State { kStateConnecting = 0 , kStateOpen , kStateClosing , kStateClosed }
 Websocket state. More...
 

Public Member Functions

 WebSocket ()
 ctor More...
 
virtual ~WebSocket ()
 NA NA. More...
 
bool init (const Delegate &delegate, const std::string &url, const std::vector< std::string > *protocols=NULL)
 The initialized method for websocket. More...
 
void send (const std::string &message)
 Sends string data to websocket server. More...
 
void send (const unsigned char *binaryMsg, unsigned int len)
 Sends binary data to websocket server. More...
 
void close ()
 Closes the connection to server. More...
 
State getReadyState ()
 Gets current state of connection. More...
 

Friends

class WebSocketCallbackWrapper
 
class WsThreadHelper
 

Member Enumeration Documentation

◆ ErrorCode

enum ErrorCode

Errors in websocket.

Enumerator
kErrorTimeout 
kErrorConnectionFailure 
kErrorUnknown 

◆ State

enum State

Websocket state.

Enumerator
kStateConnecting 
kStateOpen 
kStateClosing 
kStateClosed 

Constructor & Destructor Documentation

◆ WebSocket()

WebSocket ( )

ctor

◆ ~WebSocket()

virtual ~WebSocket ( )
virtual

NA NA.

Member Function Documentation

◆ close()

void close ( )

Closes the connection to server.

◆ getReadyState()

State getReadyState ( )

Gets current state of connection.

◆ init()

bool init ( const Delegate delegate,
const std::string &  url,
const std::vector< std::string > *  protocols = NULL 
)

The initialized method for websocket.

It needs to be invoked right after websocket instance is allocated.

Parameters
delegateThe delegate which want to receive event from websocket.
urlThe URL of websocket server.
Returns
true: Success, false: Failure NA

◆ send() [1/2]

void send ( const std::string &  message)

Sends string data to websocket server.

◆ send() [2/2]

void send ( const unsigned char *  binaryMsg,
unsigned int  len 
)

Sends binary data to websocket server.

Friends And Related Function Documentation

◆ WebSocketCallbackWrapper

friend class WebSocketCallbackWrapper
friend

◆ WsThreadHelper

friend class WsThreadHelper
friend

The documentation for this class was generated from the following file: