Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
Websocket Client

Client to make persistent connection to websocket server. More...

Classes

class  WebsocketClient
 Delegate callback type for connection of websocket client. More...
 

Typedefs

typedef Delegate< void(WebsocketClient &wsClient, const String message)> WebSocketClientMessageDelegate
 
typedef Delegate< void(WebsocketClient &wsClient, uint8_t *data, size_t size)> WebSocketClientBinaryDelegate
 Delegate callback type for received text message. More...
 
typedef Delegate< void(WebsocketClient &wsClient, bool successful)> WebSocketClientDisconnectDelegate
 Delegate callback type for received binary message. More...
 
typedef Delegate< void(WebsocketClient &wsClient, wsMode Mode)> WebSocketClientConnectedDelegate
 Delegate callback type for disconnection of websocket client. More...
 

Enumerations

enum  wsMode : uint8_t {
  Disconnected = 0,
  Connecting,
  Connected
}
 Websocket client modes enum. More...
 

Functions

 WebsocketClient::WebsocketClient (bool autoDestruct=false)
 
void WebsocketClient::setWebSocketMessageHandler (WebSocketClientMessageDelegate handler)
 
void WebsocketClient::setWebSocketDisconnectedHandler (WebSocketClientDisconnectDelegate handler)
 Set handler for websocket text messages. More...
 
void WebsocketClient::setWebSocketConnectedHandler (WebSocketClientConnectedDelegate handler)
 Set handler for websocket disconnection event. More...
 
void WebsocketClient::setWebSocketBinaryHandler (WebSocketClientBinaryDelegate handler)
 Set handler for websocket connection event. More...
 
bool WebsocketClient::connect (String url, uint32_t sslOptions=0)
 Set handler for websocket binary messages. More...
 
void WebsocketClient::sendPing ()
 Connects websocket client to server. More...
 
void WebsocketClient::sendPong ()
 Send websocket ping to server. More...
 
void WebsocketClient::disconnect ()
 Send websocket ping to server. More...
 
void WebsocketClient::sendMessage (char *msg, uint16_t length)
 Disconnects websocket client from server. More...
 
void WebsocketClient::sendMessage (String str)
 Send text message to websocket server. More...
 
void WebsocketClient::sendBinary (uint8_t *msg, uint16_t length)
 Send text message to websocket server. More...
 
wsMode WebsocketClient::getWSMode ()
 Send binary message to websocket server. More...
 
virtual void WebsocketClient::onFinished (TcpClientState finishState)
 Get websocket client mode. More...
 
virtual void WebsocketClient::onError (err_t err)
 
virtual err_t WebsocketClient::onReceive (pbuf *buf)
 
bool WebsocketClient::_verifyKey (char *buf, int size)
 
void WebsocketClient::_sendFrame (WSFrameType frameType, uint8_t *msg, uint16_t length)
 

Detailed Description

Client to make persistent connection to websocket server.

Typedef Documentation

typedef Delegate<void(WebsocketClient& wsClient, uint8_t* data, size_t size)> WebSocketClientBinaryDelegate

Delegate callback type for received text message.

Delegate callback type for disconnection of websocket client.

typedef Delegate<void(WebsocketClient& wsClient, bool successful)> WebSocketClientDisconnectDelegate

Delegate callback type for received binary message.

Enumeration Type Documentation

enum wsMode : uint8_t
strong

Websocket client modes enum.

Function Documentation

bool WebsocketClient::connect ( String  url,
uint32_t  sslOptions = 0 
)

Set handler for websocket binary messages.

Parameters
handlerDelegate callback to be run when binary message received
void WebsocketClient::disconnect ( )

Send websocket ping to server.

wsMode WebsocketClient::getWSMode ( )

Send binary message to websocket server.

Parameters
msgPointer to binary-data buffer to be send to websocket server
lengthlength of the binary-data buffer
virtual void WebsocketClient::onFinished ( TcpClientState  finishState)
protectedvirtual

Get websocket client mode.

Return values
Returntwebsocket client mode

Reimplemented from TcpClient.

void WebsocketClient::sendBinary ( uint8_t *  msg,
uint16_t  length 
)

Send text message to websocket server.

Parameters
C++String to be send to websocket server
void WebsocketClient::sendMessage ( char *  msg,
uint16_t  length 
)

Disconnects websocket client from server.

void WebsocketClient::sendMessage ( String  str)

Send text message to websocket server.

Parameters
msgPointer to NULL-terminated string buffer to be send to websocket server
lengthlength of the NULL-terminated string buffer
void WebsocketClient::sendPing ( )

Connects websocket client to server.

Parameters
urlURL address of websocket server
sslOptionsSpecify the SSL options to be used when calling websocket server over SSL
void WebsocketClient::sendPong ( )

Send websocket ping to server.

void WebsocketClient::setWebSocketBinaryHandler ( WebSocketClientBinaryDelegate  handler)

Set handler for websocket connection event.

Parameters
handlerDelegate callback to be run when websocket connects
void WebsocketClient::setWebSocketConnectedHandler ( WebSocketClientConnectedDelegate  handler)

Set handler for websocket disconnection event.

Parameters
handlerDelegate callback to be run when websocket disconnects
void WebsocketClient::setWebSocketDisconnectedHandler ( WebSocketClientDisconnectDelegate  handler)

Set handler for websocket text messages.

Parameters
handlerDelegate callback to be run when text message received