#include <ImFusion/Stream/Network/WebsocketClient.h>
WebSocket client implementation providing bidirectional communication.
More...
template<typename Payload = std::string>
class ImFusion::Network::WebsocketClient< Payload >
WebSocket client implementation providing bidirectional communication.
Implements a WebSocket client that:
- Maintains a persistent connection to a WebSocket server.
- Runs a read loop to handle incoming messages.
- Emits signals when new messages are received.
- Provides methods for sending messages to the server.
- Template Parameters
-
- Note
- Messages are sent and received asynchronously.
- Examples
- NetworkCommunication.cpp.
|
| | WebsocketClient (const std::string &ip, int port) |
| | Constructs a WebSocket client.
|
| |
| bool | connect (int connectionTimeoutMs=500) override |
| | Attempts to establish a connection to the TCP socket server with a predefined timeout when it aborts the attempt (500 milliseconds by default).
|
| |
| bool | isConnected () const override |
| | Returns true if a handshake was successful and the connection is active, false otherwise.
|
| |
| void | disconnect () override |
| | Terminates the connection and cancels the current session.
|
| |
| void | sendMessage (Payload message) override |
| | Sends a message over the network connection.
|
| |
| virtual void | sendMessage (std::string message)=0 |
| | Sends a message over the network connection.
|
| |
◆ WebsocketClient()
template<typename Payload = std::string>
Constructs a WebSocket client.
- Parameters
-
| 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 of the WebSocket server. |
◆ connect()
template<typename Payload = std::string>
| bool connect |
( |
int | connectionTimeoutMs = 500 | ) |
|
|
overridevirtual |
Attempts to establish a connection to the TCP socket server with a predefined timeout when it aborts the attempt (500 milliseconds by default).
- Returns
- true if the connection is successfully established, false otherwise.
Implements ClientConnectionBase< std::string >.
◆ isConnected()
template<typename Payload = std::string>
| bool isConnected |
( |
| ) |
const |
|
overridevirtual |
◆ disconnect()
template<typename Payload = std::string>
Terminates the connection and cancels the current session.
Pending messages for sending are still being sent. Incoming messages that have not yet been processed are discarded.
Implements ClientConnectionBase< std::string >.
◆ sendMessage()
template<typename Payload = std::string>
| void sendMessage |
( |
Payload | message | ) |
|
|
override |
Sends a message over the network connection.
Emits signalMessageSent after the message has been sent.
◆ blueprint()
template<typename Payload = std::string>
Creates a blueprint for WebSocket configuration.
- Returns
- A blueprint defining:
- Required connection parameters.
- Default property values.
- Socket construction logic.
- Note
- The blueprint is registered with ConnectionFactory by default to facilitate WebSocket creation and configuration.
The documentation for this class was generated from the following file:
- ImFusion/Stream/Network/WebsocketClient.h