Header Only Library
Websocket Server
How to use Websocket server class
References
#include "IP/InternetProtocol.hpp"
Syntax
Example Code
Variables
EOpcode
FDataFrame
FWsMessage
FRequest
FResponse
Functions
Set Socket
- Set the
adress
,port
,max connection
of socket acceptor
Get Acceptor
- Get socket acceptor
Get Sockets
- Get all sockets connected to the server
Set Max Send Buffer Size
- Set max size in bytes of send buffer
Get Max Send Buffer Size
- Get max size in bytes of send buffer
Set Split Package
- If the size of a message exceeds the maximum allowed size for the send buffer, it will be divided into smaller packets before being sent.
Get Split Package
- Get if Split Package is enabled
Send Handshake To
- Send a websocket handshake to stablish connection with
- Return false if socket is closed
- Warning: If you’re using Windows, ensure that you are sending characters compatible with UTF-8
Send Handshake Error To
- Send a websocket handshake error and close connection
- Return false if socket is closed
- Warning: If you’re using Windows, ensure that you are sending characters compatible with UTF-8
Send Str To
- Send a string message
- Return false if string is empty or socket is closed
- Warning: If you’re using Windows, ensure that you are sending characters compatible with UTF-8
Send Buffer To
- Send a buffer message
- Return false if byte array is empty or socket is closed
Send Ping To
- Send a ping to websocket server
- Return false if socket is closed
Open
- Open connection
- Return false if socket is already open or any error occurs
- Event
on_error
is triggered if any error occurs
Close
- Disconnect all clients and close connection
Disconnect Socket
- Close connection of specific socket
Get Error Code
- Get latest error code
Handshake Functions
Handshake is a http request to contact the server and requesting a WebSocket connection
Set Headers
- Set handshake headers
Get Headers
- Return a reference to handshake headers
- Use this function to modify or append values to headers
Dataframe Functions
Set RSV1
Use RSV1
Set RSV2
Use RSV2
Set RSV3
Use RSV3
Set Mask
Use Mask
Events
On Socket Accepted
- Event triggered when a new client connection is estabilished
On Bytes Transferred
- Event triggered when socket send or receive data
size_t
: bytes sentsize_t
: bytes received
On Message Sent
- Event triggered when a message is sent by specific socket
const asio::error_code &
: if error occur, error code will be different from 0
On Message Received
- Event triggered when a message is received by specific socket
FWsMessage
: message struct- Use
buffer_to_string()
function to converteraw_data
tostd::string
On Pong Received
- Event triggered when a pong message is received
On Close Notify
- Event triggered when a client send a close notification
On Close
- Event triggered when a connection is closed
On Error
- Event triggered if any error occur during async process.
const asio::error_code &
: if error occur, error code will be different from 0.- Normally, when an error occurs, the socket is automatically closed, triggering the
on_close
event.