My Project
 All Classes Functions Variables Pages
Public Member Functions | Static Public Attributes | Friends | List of all members
WebSocket Class Reference

Public Member Functions

 WebSocket (Socket socket)
 Construct a WebSocket instance.
 
virtual ~WebSocket ()
 Destructor.
 
void close (uint16_t status=CLOSE_NORMAL_CLOSURE, std::string message="")
 Close the Web socket. More...
 
WebSocketHandlergetHandler ()
 Get the current WebSocketHandler A web socket handler is a user registered class instance that is called when an incoming event received over the network needs to be handled by user code.
 
Socket getSocket ()
 Get the underlying socket for the websocket. More...
 
void send (std::string data, uint8_t sendType=SEND_TYPE_BINARY)
 Send data down the web socket See the WebSocket spec (RFC6455) section "6.1 Sending Data". We build a WebSocket frame, send the frame followed by the data. More...
 
void send (uint8_t *data, uint16_t length, uint8_t sendType=SEND_TYPE_BINARY)
 Send data down the web socket See the WebSocket spec (RFC6455) section "6.1 Sending Data". We build a WebSocket frame, send the frame followed by the data. More...
 
void setHandler (WebSocketHandler *handler)
 Set the Web socket handler associated with this Websocket. More...
 

Static Public Attributes

static const uint16_t CLOSE_NORMAL_CLOSURE = 1000
 
static const uint16_t CLOSE_GOING_AWAY = 1001
 
static const uint16_t CLOSE_PROTOCOL_ERROR = 1002
 
static const uint16_t CLOSE_CANNOT_ACCEPT = 1003
 
static const uint16_t CLOSE_NO_STATUS_CODE = 1005
 
static const uint16_t CLOSE_CLOSED_ABNORMALLY = 1006
 
static const uint16_t CLOSE_NOT_CONSISTENT = 1007
 
static const uint16_t CLOSE_VIOLATED_POLICY = 1008
 
static const uint16_t CLOSE_TOO_BIG = 1009
 
static const uint16_t CLOSE_NO_EXTENSION = 1010
 
static const uint16_t CLOSE_UNEXPECTED_CONDITION = 1011
 
static const uint16_t CLOSE_SERVICE_RESTART = 1012
 
static const uint16_t CLOSE_TRY_AGAIN_LATER = 1013
 
static const uint16_t CLOSE_TLS_HANDSHAKE_FAILURE = 1015
 
static const uint8_t SEND_TYPE_BINARY = 0x01
 
static const uint8_t SEND_TYPE_TEXT = 0x02
 

Friends

class WebSocketReader
 
class HttpServerTask
 

Member Function Documentation

void WebSocket::close ( uint16_t  status = CLOSE_NORMAL_CLOSURE,
std::string  message = "" 
)

Close the Web socket.

Parameters
[in]statusThe code passed in the close request.
[in]messageA clarification message on the close request.
Socket WebSocket::getSocket ( )

Get the underlying socket for the websocket.

Returns
The socket associated with the Web socket.
void WebSocket::send ( std::string  data,
uint8_t  sendType = SEND_TYPE_BINARY 
)

Send data down the web socket See the WebSocket spec (RFC6455) section "6.1 Sending Data". We build a WebSocket frame, send the frame followed by the data.

Parameters
[in]dataThe data to send down the WebSocket.
[in]sendTypeThe type of payload. Either SEND_TYPE_TEXT or SEND_TYPE_BINARY.
void WebSocket::send ( uint8_t *  data,
uint16_t  length,
uint8_t  sendType = SEND_TYPE_BINARY 
)

Send data down the web socket See the WebSocket spec (RFC6455) section "6.1 Sending Data". We build a WebSocket frame, send the frame followed by the data.

Parameters
[in]dataThe data to send down the WebSocket.
[in]sendTypeThe type of payload. Either SEND_TYPE_TEXT or SEND_TYPE_BINARY.
void WebSocket::setHandler ( WebSocketHandler pHandler)

Set the Web socket handler associated with this Websocket.

This will be the user supplied code that will be invoked to process incoming WebSocket events. An instance of WebSocketHandler is passed in.


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