Skip to content

UDPReceiverMulti

huggins edited this page May 10, 2023 · 1 revision

UDP Receiver Multi

A class to handle receiving UDP packets via UDP sockets.

class UDPReceiverMulti

Includes

Back to Top


Members

Access Type Name Description
Private bool allowLoopback Whether or not packets sent by the local machine should be processed.
Public bool AllowLoopback Public getter/setter for allowLoopback.
Private UdpClient client The UdpClient being used for receiving UDP packets.
Private IPEndPoint epReceive The IP endpoint being used for receiving UDP packets.
Private Exception Exception The exception that is used if the PDU Sender fails at some point during its runtime. Contains reasoning behind the failure.
Public IPAddress ipAddress The .Net container for the IP Address to use for receiving UDP messages.
Public IPAddress IPAddress Public getter/setter for ipAddress.
Private bool isCancelled Whether or not the thread for receiving UDP packets should be cancelled.
Private string LocalIPAddress The IP address of the local machine that the UDP Receiver Multi is being run on.
Private int MAX_QUEUE_SIZE The maximum number of queued PDUs before the most recent ones get removed.
Public string multicastAddress The multicast address to receive UDP packets from. DIS transient multicast groups range from 224.252.0.0 - 224.255.255.255 per IANA standards.
Public string MulticastAddress Public getter/setter for multicastAddress.
List<PDUProcessorInterface> pduProcessors List that contains all PDU Processors that will get informed when a new UDP packet is received by this UDP Receiver Multi.
Public int port The Port to receive UDP packets from. Valid Port ranges are from 1024 to 65535.
Public int Port Public getter/setter for Port.
Private Thread receiveThread The thread that is responsible for running the PDU receiver.
Private ConcurrentList<byte[]> udpPacketList The concurrent queue that houses all PDUs that have been received and are awaiting being processed.
Public bool useMulticast Whether or not multicast should be used with this receive socket.
Public bool UseMulticast Public getter/setter for useMulticast.

Back to Top


Constructors

Access Name Description
Public UDPReceiverMulti(IPAddress ipAddress, int port, IPAddress multicastAddress, bool useMulticast, bool allowLoopback) Initializes a new UDP Receiver Multi with the given information.

Events

Delegate Name Event Name Description
UnityEvent<Exception> OnFailedToConnect Called if the UDP receiver fails to connect to the given IP Address/Port.

Back to Top

Functions

Access Return Name Description
Private void asyncReceive(IAsyncResult result) The function being used by the UdpClient as the async callback when a new UDP message is received.
Private void BeginReceive() Initializes info needed on the receiveThread when it is started up.
Public void beginReceiving() Starts the receiveThread for receiving UDP messages.
Public void registerPDUProcessor(PDUProcessorInterface pduProcessor) Registers a new PDU Processor that will have received PDUs sent to it.
Public void StopReceiving() Stops receiving new UDP packets and closes associated threads.
Public void unregisterPDUProcessor(PDUProcessorInterface pduProcessor) Unregisters a PDU Processor from the UDP Receiver Multi.

Back to Top


Details

AllowLoopback

private bool allowLoopback

Whether or not packets sent by the local machine should be processed.

Back to Top


AllowLoopback

public bool AllowLoopback

Public getter/setter for allowLoopback.

Back to Top


Client

private UdpClient client

The UdpClient being used for receiving UDP packets.

Back to Top


EpReceive

private IPEndPoint epReceive

The IP endpoint being used for receiving UDP packets.

Back to Top


Exception

private Exception exception

The exception that is used if the PDU Sender fails at some point during its runtime. Contains reasoning behind the failure.

Back to Top


IPAddress

private IPAddress ipAddress

The .Net container for the IP Address to use for receiving UDP messages.

Back to Top


IPAddress

public IPAddress IPAddress

Public getter/setter for ipAddress.

Back to Top


IsCancelled

private bool isCancelled

Whether or not the thread for receiving UDP packets should be cancelled.

Back to Top


LocalIPAddress

private string LocalIPAddress

The IP address of the local machine that the UDP Receiver Multi is being run on.

Back to Top


MAX_QUEUE_SIZE

private static int MAX_QUEUE_SIZE = 1 * 1024

The maximum number of queued PDUs before the most recent ones get removed.

Back to Top


MulticastAddress

private IPAddress multicastAddress

The multicast address to receive UDP packets from. DIS transient multicast groups range from 224.252.0.0 - 224.255.255.255 per IANA standards.

Back to Top


MulticastAddress

public IPAddress MulticastAddress

Public getter/setter for multicastAddress.

Back to Top


PDUProcessors

List<PDUProcessorInterface> pduProcessors

List that contains all PDU Processors that will get informed when a new UDP packet is received by this UDP Receiver Multi.

Back to Top


Port

private int port

The Port to receive UDP packets from. Valid Port ranges are from 1024 to 65535.

Back to Top


Port

public int Port

Public getter/setter for Port.

Back to Top


ReceiveThread

private Thread receiveThread

The thread that is responsible for running the PDU receiver.

Back to Top


UDPPacketList

private ConcurrentList<byte[]> udpPacketList

The concurrent queue that houses all PDUs that have been received and are awaiting being processed.

Back to Top


UseMulticast

private bool useMulticast

Whether or not multicast should be used with this receive socket.

Back to Top


UseMulticast

public bool UseMulticast

Public getter/setter for useMulticast.

Back to Top


UDPReceiverMulti

public UDPReceiverMulti
(
    IPAddress ipAddress,
    int port,
    IPAddress multicastAddress,
    bool useMulticast,
    bool allowLoopback
)

Initializes a new UDP Receiver Multi with the given information.

Parameter Description
ipAddress The IP Address to use for receiving UDP messages.
port The Port to receive UDP packets from.
multicastAddress The multicast address to receive UDP packets from if multicast is enabled.
useMulticast Whether or not multicast should be used with this receive socket.
allowLoopback Whether or not packets sent by the local machine should be processed.

Back to Top


OnFailedToConnect

public UnityEvent<Exception> OnFailedToConnect

Called if the UDP receiver fails to connect to the given IP Address/Port.

Parameter Description
Exception The exception that contains the reasoning behind why the UDP receiver failed to connect.

Back to Top


AsyncReceive

private void asyncReceive
(
    IAsyncResult result
)

The function being used by the UdpClient as the async callback when a new UDP message is received.

Parameter Description
result The result of the asynchronous operation.

Back to Top


BeginReceive

private void BeginReceive()

Initializes info needed on the receiveThread when it is started up.

Back to Top


BeginReceiving

public void beginReceiving()

Starts the receiveThread for receiving UDP messages.

Back to Top


RegisterPDUProcessor

public void registerPDUProcessor
(
    PDUProcessorInterface pduProcessor
)

Registers a new PDU Processor that will have received PDUs sent to it.

Parameter Description
pduProcessor The new PDU Processor to register.

Back to Top


StopReceiving

public void stopReceiving()

Stops receiving new UDP packets and closes associated threads.

Back to Top


UnregisterPDUProcessor

public void unregisterPDUProcessor
(
    PDUProcessorInterface pduProcessor
)

Unregisters a PDU Processor from the UDP Receiver Multi.

Parameter Description
pduProcessor The PDU Processor to unregister.

Back to Top