ImFusion SDK 4.3
UDPSocket< Payload > Class Template Reference

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

UDP socket implementation for network communication. More...

+ Inheritance diagram for UDPSocket< Payload >:

Detailed Description

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

UDP socket implementation for network communication.

Provides a UDP socket that can send and receive messages of type Payload. It manages its own network thread for asynchronous operations.

Template Parameters
PayloadThe message type for the socket, either std::string (default) or ByteBuffer.
Note
Messages are sent and received asynchronously.

Public Member Functions

 UDPSocket (const std::string &peerIp, unsigned short peerPort, const std::string &ownIp="0.0.0.0", unsigned short ownPort=0)
 Constructs a UDP socket.
 
 ~UDPSocket () override
 Cleans up network resources.
 
bool run ()
 Starts a listening thread that processes incoming messages and emits them via signalNewMessage.
 
bool stop ()
 Stops the listening thread.
 
bool isRunning () const
 Checks the current status of the socket.
 
void sendMessage (Payload message) override
 Sends a message to the configured peer.
 
- Public Member Functions inherited from 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 socket configuration.
 

Additional Inherited Members

- Public Attributes inherited from TypedConnectionBase< std::string >
ProtectedSignal< std::shared_ptr< std::string > > signalNewMessage
 Signal emitted when a new message is received.
 
ProtectedSignal< std::shared_ptr< std::string > > signalMessageSent
 Signal emitted when a message is sent.
 

Constructor & Destructor Documentation

◆ UDPSocket()

template<typename Payload = std::string>
UDPSocket ( const std::string & peerIp,
unsigned short peerPort,
const std::string & ownIp = "0.0.0.0",
unsigned short ownPort = 0 )
explicit

Constructs a UDP socket.

Parameters
peerIpIP address of the remote peer.
peerPortPort number of the remote peer.
ownIpLocal IP address to bind to (default: "0.0.0.0").
ownPortLocal port to bind to (default: 0 for automatic assignment).
Note
If ownPort is 0, the system automatically assigns an available port.

Member Function Documentation

◆ run()

template<typename Payload = std::string>
bool run ( )

Starts a listening thread that processes incoming messages and emits them via signalNewMessage.

Returns
true if successfully started, false otherwise.

◆ stop()

template<typename Payload = std::string>
bool stop ( )

Stops the listening thread.

Returns
true if successfully stopped, false otherwise.

◆ isRunning()

template<typename Payload = std::string>
bool isRunning ( ) const

Checks the current status of the socket.

Returns
true if the socket is running and listening for messages, false otherwise.

◆ sendMessage()

template<typename Payload = std::string>
void sendMessage ( Payload message)
override

Sends a message to the configured peer.

Parameters
messageThe message to be sent
Note
The message is sent asynchronously to the peer specified in the constructor.

◆ blueprint()

template<typename Payload = std::string>
static ConnectionBlueprint< Payload > blueprint ( )
static

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

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close