![]() |
ImFusion C++ SDK 4.4.0
|
#include <ImFusion/Stream/Network/WebsocketServer.h>
Websocket server implementation providing bidirectional communication. More...
Websocket server implementation providing bidirectional communication.
Implements a WebSocket server that:
| Payload | The message type for the socket, either std::string (default) or ByteBuffer. |
Public Member Functions | |
| WebsocketServer (const std::string &ip, int port, int threads=1) | |
| Initializes a WebSocket server that listens on the specified address {ip}:{port}. | |
| ~WebsocketServer () override | |
| Cleans up resources. If the server has not been stopped yet, returns after stopping is complete. | |
| bool | run () override |
| Starts listening for incoming connections. | |
| bool | stop () override |
| Stops listening and terminates all open connections. | |
| bool | isRunning () const override |
| Returns whether the server is actively listening for connections. | |
| bool | isReadyToRun () const |
| Returns true if the server was instantiated correctly and could be started, false otherwise, e.g if the selected combination {ip}:{port} is already in use by another connection. | |
| size_t | connectedClients () const override |
| Returns the number of currently connected clients. | |
| void | sendMessage (Payload message) override |
| Sends a message to all connected clients. | |
| std::string | address () const override |
| Returns the address of the server in the format {ip}:{port} (e.g., 127.0.0.1:5678). | |
| Public Member Functions inherited from ImFusion::Network::TypedConnectionBase< std::string > | |
| virtual void | sendMessage (std::string message)=0 |
| Sends a message over the network connection. | |
Static Public Member Functions | |
| static ConnectionBlueprint< Payload > | blueprint () |
| Creates a blueprint for WebSocket server configuration. | |
Public Attributes | |
| ProtectedSignal< bool, std::string, int, bool * > | signalClientConnected |
| Signal triggered when a client connection is established or closed. | |
| Public Attributes inherited from ImFusion::Network::ServerConnectionBase< std::string > | |
| ProtectedSignal< bool > | signalClientConnected |
| Signal emitted when a new client connects (true) or when a client disconnects (false). | |
| Public Attributes inherited from ImFusion::Network::TypedConnectionBase< std::string > | |
| ProtectedSignal< std::shared_ptr< const std::string > > | signalNewMessage |
| Signal emitted when a new message is received. | |
| ProtectedSignal< std::shared_ptr< const std::string > > | signalMessageSent |
| Signal emitted when a message is sent. | |
|
explicit |
Initializes a WebSocket server that listens on the specified address {ip}:{port}.
| ip | The IP address of the WebSocket server. Must be an IPv4 address in the form "xxx.xxx.xxx.xxx" or "localhost". |
| port | The port number on which the server listens. |
| threads | The number of threads allocated for the I/O context. The number determines how many messages can be processed simultaneously from different clients.
|
|
overridevirtual |
Starts listening for incoming connections.
Implements ImFusion::Network::ServerConnectionBase< std::string >.
|
overridevirtual |
Stops listening and terminates all open connections.
Pending messages for sending are still being sent. Incoming messages that have not yet been processed are discarded.
Implements ImFusion::Network::ServerConnectionBase< std::string >.
|
overridevirtual |
Returns whether the server is actively listening for connections.
Implements ImFusion::Network::ServerConnectionBase< std::string >.
|
overridevirtual |
Returns the number of currently connected clients.
Implements ImFusion::Network::ServerConnectionBase< std::string >.
|
overridevirtual |
Returns the address of the server in the format {ip}:{port} (e.g., 127.0.0.1:5678).
Implements ImFusion::Network::ServerConnectionBase< std::string >.
|
static |
Creates a blueprint for WebSocket server configuration.
| ProtectedSignal<bool, std::string, int, bool*> ImFusion::Network::WebsocketServer< Payload >::signalClientConnected |
Signal triggered when a client connection is established or closed.
| state | The connection state (true if connected, false if disconnected). |
| hostPort | Host and port information for the connection in the form {ip}:{port}. |
| refuse | A pointer to a boolean flag that can be modified by the receiver.
|
Example usage to refuse the connection: