CppServer
1.0.0.0
C++ Server Library
|
WebSocket server. More...
#include <websocket_server.h>
Public Member Functions | |
WebSocketServer (std::shared_ptr< Service > service, InternetProtocol protocol, int port) | |
Initialize WebSocket server with a given Asio service, protocol and port number. More... | |
WebSocketServer (std::shared_ptr< Service > service, const std::string &address, int port) | |
Initialize WebSocket server with a given Asio service, IP address and port number. More... | |
WebSocketServer (std::shared_ptr< Service > service, const asio::ip::tcp::endpoint &endpoint) | |
Initialize WebSocket server with a given Asio service and endpoint. More... | |
WebSocketServer (const WebSocketServer &)=delete | |
WebSocketServer (WebSocketServer &&)=default | |
virtual | ~WebSocketServer ()=default |
WebSocketServer & | operator= (const WebSocketServer &)=delete |
WebSocketServer & | operator= (WebSocketServer &&)=default |
std::shared_ptr< Service > & | service () noexcept |
Get the Asio service. More... | |
asio::ip::tcp::endpoint & | endpoint () noexcept |
Get the server endpoint. More... | |
WebSocketServerCore & | core () noexcept |
Get the WebSocket server core. More... | |
uint64_t | current_sessions () const noexcept |
Get the number of sessions currently connected to this server. More... | |
uint64_t | messages_sent () const noexcept |
Get the number messages sent by this server. More... | |
uint64_t | messages_received () const noexcept |
Get the number messages received by this server. More... | |
uint64_t | bytes_sent () const noexcept |
Get the number of bytes sent by this server. More... | |
uint64_t | bytes_received () const noexcept |
Get the number of bytes received by this server. More... | |
bool | IsStarted () const noexcept |
Is the server started? More... | |
bool | Start () |
Start the server. More... | |
bool | Stop () |
Stop the server. More... | |
bool | Restart () |
Restart the server. More... | |
bool | Multicast (const void *buffer, size_t size, websocketpp::frame::opcode::value opcode=websocketpp::frame::opcode::binary) |
Multicast data to all connected sessions. More... | |
bool | Multicast (const std::string &text, websocketpp::frame::opcode::value opcode=websocketpp::frame::opcode::text) |
Multicast a text string to all connected sessions. More... | |
bool | Multicast (const WebSocketMessage &message) |
Multicast a message to all connected sessions. More... | |
bool | DisconnectAll () |
Disconnect all connected sessions. More... | |
Protected Member Functions | |
virtual void | onStarted () |
Handle server started notification. More... | |
virtual void | onStopped () |
Handle server stopped notification. More... | |
virtual void | onConnected (std::shared_ptr< TSession > &session) |
Handle new session connected notification. More... | |
virtual void | onDisconnected (std::shared_ptr< TSession > &session) |
Handle session disconnected notification. More... | |
virtual void | onError (int error, const std::string &category, const std::string &message) |
Handle error notification. More... | |
Friends | |
template<class TSomeServer , class TSomeSession > | |
class | WebSocketSession |
WebSocket server.
WebSocket server is used to connect, disconnect and manage WebSocket sessions.
Thread-safe.
Definition at line 32 of file websocket_server.h.
|
inlineexplicit |
Initialize WebSocket server with a given Asio service, protocol and port number.
service | - Asio service |
protocol | - Protocol type |
port | - Port number |
Definition at line 13 of file websocket_server.inl.
|
inlineexplicit |
Initialize WebSocket server with a given Asio service, IP address and port number.
service | - Asio service |
address | - IP address |
port | - Port number |
Definition at line 40 of file websocket_server.inl.
|
inlineexplicit |
Initialize WebSocket server with a given Asio service and endpoint.
service | - Asio service |
endpoint | - Server endpoint |
Definition at line 59 of file websocket_server.inl.
|
delete |
|
default |
|
virtualdefault |
|
inlinenoexcept |
Get the number of bytes received by this server.
Definition at line 81 of file websocket_server.h.
|
inlinenoexcept |
Get the number of bytes sent by this server.
Definition at line 79 of file websocket_server.h.
|
inlinenoexcept |
Get the WebSocket server core.
Definition at line 70 of file websocket_server.h.
|
inlinenoexcept |
Get the number of sessions currently connected to this server.
Definition at line 73 of file websocket_server.h.
|
inline |
Disconnect all connected sessions.
Definition at line 284 of file websocket_server.inl.
|
inlinenoexcept |
Get the server endpoint.
Definition at line 68 of file websocket_server.h.
|
inlinenoexcept |
Is the server started?
Definition at line 84 of file websocket_server.h.
|
inlinenoexcept |
Get the number messages received by this server.
Definition at line 77 of file websocket_server.h.
|
inlinenoexcept |
Get the number messages sent by this server.
Definition at line 75 of file websocket_server.h.
|
inline |
Multicast data to all connected sessions.
buffer | - Buffer to send |
size | - Buffer size |
opcode | - Data opcode (default is websocketpp::frame::opcode::binary) |
Definition at line 200 of file websocket_server.inl.
|
inline |
Multicast a text string to all connected sessions.
text | - Text string to send |
opcode | - Data opcode (default is websocketpp::frame::opcode::text) |
Definition at line 223 of file websocket_server.inl.
|
inline |
Multicast a message to all connected sessions.
message | - Message to send |
Definition at line 240 of file websocket_server.inl.
|
inlineprotectedvirtual |
Handle new session connected notification.
session | - Connected session |
Definition at line 140 of file websocket_server.h.
|
inlineprotectedvirtual |
Handle session disconnected notification.
session | - Disconnected session |
Definition at line 145 of file websocket_server.h.
|
inlineprotectedvirtual |
Handle error notification.
error | - Error code |
category | - Error category |
message | - Error message |
Definition at line 153 of file websocket_server.h.
|
inlineprotectedvirtual |
Handle server started notification.
Definition at line 132 of file websocket_server.h.
|
inlineprotectedvirtual |
Handle server stopped notification.
Definition at line 134 of file websocket_server.h.
|
delete |
|
default |
|
inline |
Restart the server.
Definition at line 188 of file websocket_server.inl.
|
inlinenoexcept |
Get the Asio service.
Definition at line 66 of file websocket_server.h.
|
inline |
Start the server.
Definition at line 96 of file websocket_server.inl.
|
inline |
Stop the server.
Definition at line 155 of file websocket_server.inl.
|
friend |
Definition at line 35 of file websocket_server.h.