STTNet
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | List of all members
stt::network::WebSocketServerFDHandler Class Reference

WebSocket protocol operation class Only pass in the socket, then use this class for WebSocket operations. More...

#include <sttnet_English.h>

Inheritance diagram for stt::network::WebSocketServerFDHandler:
stt::network::TcpFDHandler

Public Member Functions

void setFD (const int &fd, SSL *ssl=nullptr, const bool &flag1=false, const bool &flag2=true)
 Initialize the object, pass in socket and other parameters. More...
 
int getMessage (TcpFDInf &Tcpinf, WebSocketFDInformation &Websocketinf, const unsigned long &buffer_size, const int &ii=1)
 Get a websocket message. More...
 
bool sendMessage (const std::string &msg, const std::string &type="0001")
 Send a websocket message. More...
 

Detailed Description

WebSocket protocol operation class Only pass in the socket, then use this class for WebSocket operations.

Member Function Documentation

int stt::network::WebSocketServerFDHandler::getMessage ( TcpFDInf Tcpinf,
WebSocketFDInformation Websocketinf,
const unsigned long &  buffer_size,
const int &  ii = 1 
)

Get a websocket message.

Parameters
Tcpinfsaves the underlying TCP status information
Websocketinfsaves the websocket protocol status information
buffer_sizeThe size of the server-defined parsing buffer (in bytes).
iiRecord the number of resolutions, which can be used in some cases The default is 1
Returns
-1: Failed to get 0: General message 1: Close frame 2: Heartbeat confirmation message 3: Heartbeat message 4:waiting data
Note
TcpInf.status

0 Initial state 1 Confirmation message type 2 Acknowledgment message length 3 Receiveing mask 4 Receiving messages

bool stt::network::WebSocketServerFDHandler::sendMessage ( const std::string &  msg,
const std::string &  type = "0001" 
)

Send a websocket message.

Parameters
msgWebsocket message to be sent
typeCustom field specifying the message type (usually the WebSocket frame's opcode) Conventional format is "1000" + type, where:
  • "0001" represents text frame (Text Frame)
  • "0010" represents binary frame (Binary Frame)
  • "1000" represents connection close (Close Frame)
  • "1001" represents Ping frame
  • "1010" represents Pong frame Please use according to internal conventions, text frame (Text Frame) is used by default
Returns
true: Sent successfully, false: Sending failed
void stt::network::WebSocketServerFDHandler::setFD ( const int &  fd,
SSL *  ssl = nullptr,
const bool &  flag1 = false,
const bool &  flag2 = true 
)
inline

Initialize the object, pass in socket and other parameters.

Parameters
fdSocket
sslTLS encrypted SSL handle (default is nullptr)
flag1true: Enable non-blocking mode, false: Enable blocking mode (default is false, i.e., blocking mode)
flag2true: Enable SO_REUSEADDR mode, false: Do not enable SO_REUSEADDR mode (default is true, i.e., enable mode)

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