|
VR-Engage
2.2
|
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>
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 | |
| DtVreMessageFactory * | myMessageFactory |
| UInt64 | myId |
| std::vector< DtVreMessageBundle * > | myMessageBundles |
| std::string | myApplicationName |
Additional Inherited Members | |
Static Public Member Functions inherited from makVre::DtNetworkForwarder | |
| static int | maxBundleSize () |
| makVre::DtUdpNetworkForwarder::DtUdpNetworkForwarder | ( | DtVreMessageFactory * | factory, |
| std::string | deviceAddress, | ||
| std::string | destinationAddress, | ||
| int | port ) |
Constructor.
| factory | Pointer to the message factory for creating messages from raw data |
| deviceAddress | Network interface address to bind to (e.g., "0.0.0.0" for all interfaces) |
| destinationAddress | Destination address for outgoing messages (can be multicast/broadcast) |
| port | UDP 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.
|
overridevirtual |
Virtual destructor.
Cleans up resources, including the UDP socket if it exists.
|
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.
|
overridevirtual |
Enables the UDP network forwarder.
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.
|
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.
|
virtual |
Processes incoming UDP messages.
| dt | Delta 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.
|
protectedvirtual |
Processes a received UDP packet containing VREngage messages.
| buffer | Pointer to the buffer containing the received data |
| length | Length of the received data in bytes |
| from | Endpoint 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.
|
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).
|
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.
|
protected |
UDP port number for both sending and receiving.
|
protected |