-
Notifications
You must be signed in to change notification settings - Fork 6
UDPReceiverMulti
A class to handle receiving UDP packets via UDP sockets.
class UDPReceiverMulti| 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. |
| 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. |
| Delegate Name | Event Name | Description |
|---|---|---|
| UnityEvent<Exception> | OnFailedToConnect | Called if the UDP receiver fails to connect to the given IP Address/Port. |
| 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. |
private bool allowLoopbackWhether or not packets sent by the local machine should be processed.
public bool AllowLoopbackPublic getter/setter for allowLoopback.
private UdpClient clientThe UdpClient being used for receiving UDP packets.
private IPEndPoint epReceiveThe IP endpoint being used for receiving UDP packets.
private Exception exceptionThe exception that is used if the PDU Sender fails at some point during its runtime. Contains reasoning behind the failure.
private IPAddress ipAddressThe .Net container for the IP Address to use for receiving UDP messages.
public IPAddress IPAddressPublic getter/setter for ipAddress.
private bool isCancelledWhether or not the thread for receiving UDP packets should be cancelled.
private string LocalIPAddressThe IP address of the local machine that the UDP Receiver Multi is being run on.
private static int MAX_QUEUE_SIZE = 1 * 1024The maximum number of queued PDUs before the most recent ones get removed.
private IPAddress multicastAddressThe 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 IPAddress MulticastAddressPublic getter/setter for multicastAddress.
List<PDUProcessorInterface> pduProcessorsList that contains all PDU Processors that will get informed when a new UDP packet is received by this UDP Receiver Multi.
private int portThe Port to receive UDP packets from. Valid Port ranges are from 1024 to 65535.
public int PortPublic getter/setter for Port.
private Thread receiveThreadThe thread that is responsible for running the PDU receiver.
private ConcurrentList<byte[]> udpPacketListThe concurrent queue that houses all PDUs that have been received and are awaiting being processed.
private bool useMulticastWhether or not multicast should be used with this receive socket.
public bool UseMulticastPublic getter/setter for useMulticast.
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. |
public UnityEvent<Exception> OnFailedToConnectCalled 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. |
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. |
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.
| Parameter | Description |
|---|---|
| pduProcessor | The new PDU Processor to register. |
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.
| Parameter | Description |
|---|---|
| pduProcessor | The PDU Processor to unregister. |