8 #ifndef COMPONENTS_WEBSOCKET_H_
9 #define COMPONENTS_WEBSOCKET_H_
26 uint8_t* pMask =
nullptr,
27 size_t bufferSize = 2048);
52 virtual void onError(std::string error);
62 static const uint16_t CLOSE_NORMAL_CLOSURE = 1000;
63 static const uint16_t CLOSE_GOING_AWAY = 1001;
64 static const uint16_t CLOSE_PROTOCOL_ERROR = 1002;
65 static const uint16_t CLOSE_CANNOT_ACCEPT = 1003;
66 static const uint16_t CLOSE_NO_STATUS_CODE = 1005;
67 static const uint16_t CLOSE_CLOSED_ABNORMALLY = 1006;
68 static const uint16_t CLOSE_NOT_CONSISTENT = 1007;
69 static const uint16_t CLOSE_VIOLATED_POLICY = 1008;
70 static const uint16_t CLOSE_TOO_BIG = 1009;
71 static const uint16_t CLOSE_NO_EXTENSION = 1010;
72 static const uint16_t CLOSE_UNEXPECTED_CONDITION = 1011;
73 static const uint16_t CLOSE_SERVICE_RESTART = 1012;
74 static const uint16_t CLOSE_TRY_AGAIN_LATER = 1013;
75 static const uint16_t CLOSE_TLS_HANDSHAKE_FAILURE = 1015;
77 static const uint8_t SEND_TYPE_BINARY = 0x01;
78 static const uint8_t SEND_TYPE_TEXT = 0x02;
83 void close(uint16_t status = CLOSE_NORMAL_CLOSURE, std::string message =
"");
86 void send(std::string data, uint8_t sendType = SEND_TYPE_BINARY);
87 void send(uint8_t* data, uint16_t length, uint8_t sendType = SEND_TYPE_BINARY);
Encapsulate a socket.
Definition: Socket.h:62
A task that will watch web socket inputs.
Definition: WebSocket.cpp:96
virtual void onError(std::string error)
The default onError handler. If no over-riding handler is provided for the "error" event...
Definition: WebSocket.cpp:230
Socket getSocket()
Get the underlying socket for the websocket.
Definition: WebSocket.cpp:312
virtual void onMessage(WebSocketInputStreambuf *pWebSocketInputStreambuf, WebSocket *pWebSocket)
The default onData handler. If no over-riding handler is provided for the "message" event...
Definition: WebSocket.cpp:220
WebSocket(Socket socket)
Construct a WebSocket instance.
Definition: WebSocket.cpp:239
virtual void onClose()
The default onClose handler. If no over-riding handler is provided for the "close" event...
Definition: WebSocket.cpp:204
Definition: WebSocket.h:60
virtual ~WebSocketHandler()
Destructor.
Definition: WebSocket.cpp:511
Definition: WebSocket.h:47
Be an HTTP server task. Here we define a Task that will be run when the HTTP server starts...
Definition: HttpServer.cpp:53
void setHandler(WebSocketHandler *handler)
Set the Web socket handler associated with this Websocket.
Definition: WebSocket.cpp:382
virtual ~WebSocket()
Destructor.
Definition: WebSocket.cpp:251
void close(uint16_t status=CLOSE_NORMAL_CLOSURE, std::string message="")
Close the Web socket.
Definition: WebSocket.cpp:262
WebSocketHandler * getHandler()
Get the current WebSocketHandler A web socket handler is a user registered class instance that is cal...
Definition: WebSocket.cpp:303
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"...
Definition: WebSocket.cpp:324