ImFusion C++ SDK 4.5.0
ImFusion::Network::TCPSocketClient< Payload > Class Template Reference

#include <ImFusion/Stream/Network/TCPSocketClient.h>

TCP socket client implementation providing bidirectional communication. More...

Inheritance diagram for ImFusion::Network::TCPSocketClient< Payload >:

Detailed Description

template<typename Payload = std::string>
class ImFusion::Network::TCPSocketClient< Payload >

TCP socket client implementation providing bidirectional communication.

Implements a TCP socket (non-web socket) client that:

  • Maintains a persistent connection to a TCP socket server.
  • Runs a read loop for incoming messages.
  • Emits signals when new messages are received.
  • Provides methods for sending messages to the server.
Template Parameters
PayloadThe message type for the socket, either std::string (default) or ByteBuffer.
Note
Messages are sent and received asynchronously.

Public Member Functions

 TCPSocketClient (const std::string &ip, int port)
 Constructs a TCP socket 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.
Public Member Functions inherited from ImFusion::Network::TypedConnectionBase< std::string >
virtual void sendMessage (std::string message)=0
 Sends a message over the network connection.
Public Member Functions inherited from ImFusion::SignalReceiver
 SignalReceiver ()=default
 Default constructor.
 SignalReceiver (const SignalReceiver &other)
 Copy constructor, does not copy any existing signal connections from other.
SignalReceiveroperator= (SignalReceiver rhs)
 Assignment operator, disconnects all existing connections, does not copy any existing signal connections from rhs.
virtual ~SignalReceiver ()
 Virtual destructor disconnects from all connected signals.

Static Public Member Functions

static ConnectionBlueprint< Payload > blueprint ()
 Creates a blueprint for TCP socket configuration.

Additional Inherited Members

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.
Protected Member Functions inherited from ImFusion::SignalReceiver
void disconnectAll ()
 Disconnects all existing connections.

Constructor & Destructor Documentation

◆ TCPSocketClient()

template<typename Payload = std::string>
ImFusion::Network::TCPSocketClient< Payload >::TCPSocketClient ( const std::string & ip,
int port )
explicit

Constructs a TCP socket client.

Parameters
ipThe IP address of the TCP socket server. Must be an IPv4 address in the form "xxx.xxx.xxx.xxx" or "localhost".
portThe port number of the TCP socket server.

Member Function Documentation

◆ connect()

template<typename Payload = std::string>
bool ImFusion::Network::TCPSocketClient< Payload >::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 ImFusion::Network::ClientConnectionBase< std::string >.

◆ isConnected()

template<typename Payload = std::string>
bool ImFusion::Network::TCPSocketClient< Payload >::isConnected ( ) const
overridevirtual

Returns true if a handshake was successful and the connection is active, false otherwise.

Implements ImFusion::Network::ClientConnectionBase< std::string >.

◆ disconnect()

template<typename Payload = std::string>
void ImFusion::Network::TCPSocketClient< Payload >::disconnect ( )
overridevirtual

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 ImFusion::Network::ClientConnectionBase< std::string >.

◆ sendMessage()

template<typename Payload = std::string>
void ImFusion::Network::TCPSocketClient< Payload >::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>
ConnectionBlueprint< Payload > ImFusion::Network::TCPSocketClient< Payload >::blueprint ( )
static

Creates a blueprint for TCP socket 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 TCP socket creation and configuration.

The documentation for this class was generated from the following file:
  • ImFusion/Stream/Network/TCPSocketClient.h
Search Tab / S to search, Esc to close