Status & Roadmap
Authors & License
Funding Ultimate++
Search on this site

SourceForge.net Logo



class WebSocket

Provides the WebSocket protocol support. WebSocket is a wrapper over existing TcpSocket connection, which performs server handshake by calling WebAccept method.



Public Method List


bool WebAccept(TcpSocket& socket, HttpHeader& hdr)

Attempts to open websocket connection with socket, hdr is HTTP header read from socket - prereading allows to distinguish between websocket and normal HTTP connection to server.



bool WebAccept(TcpSocket& socket)

Reads HTTP header from socket and calls other WebAccept variant.



bool ReceiveRaw()

Recieves the message. This variant does not automatically handle PING and CLOSE messages. Returns true on success.



String Receive()

Recieves the message. PING and CLOSE messages are handled and are not returned; PING message is replied with PONG and not reported to client - Recieve does not return and waits for the next message, CLOSE is replied by CLOSE and Recieve returns. Returns the content of message recieved or String::GetVoid() if there was none. Note: If WaitRead was used to wait for read on socket before calling Recieve, returning String::GetVoid() means that connection was broken.



bool IsFin()

Returns true if the last message was marked as final.



int GetOpCode() const

Returns the websocket opcode of the last recieved message.



bool IsText() const

Returns true if the last message recieved was text.



bool IsBinary() const

Returns true if the last message recieved was binary.



bool IsClosed() const

Returns true if CLOSE message was recieved.



String GetData() const

Returns the content of the last message.



bool SendRaw(int hdr, const void *data, int64 len)

Sends the message, hdr is used as the first byte of websocket protocol. Returns true on success.



bool SendText(const void *data, int64 len, bool fin = true)

bool SendText(const String& data, bool fin = true)

Sends the text message. Returns true on success.



bool SendBinary(const void *data, int64 len, bool fin = true)

bool SendBinary(const String& data, bool fin = true)

Sends the binary message. Returns true on success.



void Close()

Closes the websocket.



bool IsOpen() const

Returns true if WebSocket is associated with open socket.



bool IsError() const

Returns true if WebSocket is associated with socket and this socket returns IsError.



void ClearError()

Clears error in associated socket (if any).



int GetError() const

Returns error-code in associated socket, or zero if there is none.



String GetErrorDesc() const

Returns error descroption in associated socket, or empty string if there is none.



WebSocket& MaxLen(int64 maxlen_)

Sets the maximum length of recieved message to maxlen . Default is 10M.



Last edit by cxl on 12/08/2016. Do you want to contribute?. T++