VR-Engage  2.2
Loading...
Searching...
No Matches
makVre::DtUdpNetworkForwarder Class Reference

Detailed Description

This class implements a network forwarder that uses UDP sockets to send and receive VREngage messages over the network. It manages a UDP socket bound to a specific device and port, sending messages to a configured destination address. The forwarder receives incoming messages, processes them, and forwards them to the message manager for handling.

#include <udpNetworkForwarder.h>

Inheritance diagram for makVre::DtUdpNetworkForwarder:
[legend]

Public Member Functions

 DtUdpNetworkForwarder (DtVreMessageFactory *factory, std::string deviceAddress, std::string destinationAddress, int port)
 
virtual ~DtUdpNetworkForwarder () override
 
virtual void flush () override
 
virtual bool enable () override
 
virtual void disable () override
 
virtual void tick (double dt)
 
- Public Member Functions inherited from makVre::DtNetworkForwarder
 DtNetworkForwarder (DtVreMessageFactory *factory)
 
virtual ~DtNetworkForwarder ()
 
virtual void forwardEvents (const std::string &messageType)
 
virtual void stopForwardingEvents (const std::string &messageType)
 
virtual void setApplicationName (const std::string &applicationName)
 
virtual std::string applicationName ()
 

Protected Member Functions

virtual void handleBuffer (char *buffer, int length, DtInetEndpoint &from)
 
- Protected Member Functions inherited from makVre::DtNetworkForwarder
virtual makVre::DtVreMessageResult netSendMessage (makVre::DtVreMessage *msg)
 
virtual makVre::DtVreMessageResult handleForwardMessage (makVre::DtVreMessage *msg)
 
virtual makVre::DtVreMessageResult handleStopForwardMessage (makVre::DtVreMessage *msg)
 
virtual makVre::DtVreMessageResult handleRequestForwardMessage (makVre::DtVreMessage *msg)
 
virtual makVre::DtVreMessageResult handleRequestStopForwardMessage (makVre::DtVreMessage *msg)
 

Protected Attributes

std::string myDeviceAddress
 
std::string myDestinationAddress
 
int myPort
 
DtInetUdpSocket * mySocket
 
- Protected Attributes inherited from makVre::DtNetworkForwarder
DtVreMessageFactorymyMessageFactory
 
UInt64 myId
 
std::vector< DtVreMessageBundle * > myMessageBundles
 
std::string myApplicationName
 

Additional Inherited Members

- Static Public Member Functions inherited from makVre::DtNetworkForwarder
static int maxBundleSize ()
 

Constructor & Destructor Documentation

◆ DtUdpNetworkForwarder()

makVre::DtUdpNetworkForwarder::DtUdpNetworkForwarder ( DtVreMessageFactory * factory,
std::string deviceAddress,
std::string destinationAddress,
int port )

Constructor.

Parameters
factoryPointer to the message factory for creating messages from raw data
deviceAddressNetwork interface address to bind to (e.g., "0.0.0.0" for all interfaces)
destinationAddressDestination address for outgoing messages (can be multicast/broadcast)
portUDP port number for both sending and receiving

Initializes a new UDP network forwarder with the specified message factory and network parameters. The forwarder binds to the specified device address and port for receiving messages and sends messages to the specified destination address.

◆ ~DtUdpNetworkForwarder()

virtual makVre::DtUdpNetworkForwarder::~DtUdpNetworkForwarder ( )
overridevirtual

Virtual destructor.

Cleans up resources, including the UDP socket if it exists.

Member Function Documentation

◆ flush()

virtual void makVre::DtUdpNetworkForwarder::flush ( )
overridevirtual

Flushes bundled messages to the network via UDP.

This method sends all accumulated message bundles to the network through the UDP socket. It checks that the socket is valid and operational before sending. Each bundle with content is sent as a single UDP packet to the configured destination address and port.

Implements the pure virtual method from DtNetworkForwarder.

Implements makVre::DtNetworkForwarder.

◆ enable()

virtual bool makVre::DtUdpNetworkForwarder::enable ( )
overridevirtual

Enables the UDP network forwarder.

Returns
True if the forwarder was successfully enabled, false otherwise

This method enables the UDP network forwarder by creating and configuring the UDP socket. It configures the socket with the specified device address, destination address, and port. The socket is set to non-blocking mode and opened for communication. If the socket cannot be opened, the method returns false.

Overrides the base class implementation to add UDP-specific initialization.

Reimplemented from makVre::DtNetworkForwarder.

◆ disable()

virtual void makVre::DtUdpNetworkForwarder::disable ( )
overridevirtual

Disables the UDP network forwarder.

This method disables the UDP network forwarder by closing and deleting the UDP socket. After this method is called, no more messages will be sent or received until enable() is called again.

Overrides the base class implementation to add UDP-specific cleanup.

Reimplemented from makVre::DtNetworkForwarder.

◆ tick()

virtual void makVre::DtUdpNetworkForwarder::tick ( double dt)
virtual

Processes incoming UDP messages.

Parameters
dtDelta time in seconds since the last tick (not used)

This method polls the UDP socket for incoming messages, processes them, and forwards them to the message manager. It continues reading from the socket until there are no more messages available or an error occurs. If the socket becomes invalid, it is closed and deleted.

This method should be called regularly (e.g., once per frame) to ensure timely processing of incoming messages.

◆ handleBuffer()

virtual void makVre::DtUdpNetworkForwarder::handleBuffer ( char * buffer,
int length,
DtInetEndpoint & from )
protectedvirtual

Processes a received UDP packet containing VREngage messages.

Parameters
bufferPointer to the buffer containing the received data
lengthLength of the received data in bytes
fromEndpoint information about the sender

This method extracts VREngage messages from a received UDP packet and queues them for processing by the message manager. It iterates through the buffer, creating messages using the message factory, and filtering out messages that originated from this forwarder to prevent loops.

Member Data Documentation

◆ myDeviceAddress

std::string makVre::DtUdpNetworkForwarder::myDeviceAddress
protected

Network interface address to bind to.

This is the address of the network interface on which the UDP socket will listen for incoming messages (e.g., "0.0.0.0" for all interfaces).

◆ myDestinationAddress

std::string makVre::DtUdpNetworkForwarder::myDestinationAddress
protected

Destination address for outgoing messages.

This is the address to which outgoing messages will be sent. It can be a multicast or broadcast address to reach multiple receivers.

◆ myPort

int makVre::DtUdpNetworkForwarder::myPort
protected

UDP port number for both sending and receiving.

◆ mySocket

DtInetUdpSocket* makVre::DtUdpNetworkForwarder::mySocket
protected

Pointer to the UDP socket used for communication.

This socket is created in enable() and destroyed in disable(). It is used for both sending outgoing messages and receiving incoming messages.


The documentation for this class was generated from the following file: