Skip to content

PDUSender

Quintin edited this page May 16, 2023 · 2 revisions

PDU Sender

The PDU Sender is required for setting up UDP send sockets.

public class PDUSender
  : MonoBehaviour

Includes

Back to Top


Members

Access Type Name Description
Public bool autoConnectAtStart Whether or not to auto connect the receive address on start.
Public EConnectionType ConnectionType The type of connection used in sending out the PDUs.
Private DataOutputStream dos The data stream that is used to convert PDUs to bytes prior to emitting them as 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 string ipAddressString The IP Address to receive UDP packets from. An IP Address of 0.0.0.0 listens to all connection on the specified port.
Public int maxQueueSize The maximum number of queued PDUs before the most recent ones get removed.
Private ConcurrentQueue<byte[]> pdus The concurrent queue that houses all PDUs that are awaiting being sent on the network.
Public int port The Port to receive UDP packets from. Valid Port ranges are from 1024 to 65535.
Private bool sending Whether or not the PDU Sender is currently sending PDUs.
Private Thread thread The thread that is responsible for running the PDU Sender.

Back to Top


Events

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

Functions

Access Return Name Description
Private void Awake() Awake is called when the script instance is being loaded.
Public void ChangeAddress(string IP, int port) Changes the IP of the UDP Sender safely
Public void Init() Starts up the thread from the desired ip.
Public bool IsConnected() Gets whether or not the PDU Sender is currently connected.
Private Static IPAddress LocalIPAddress() Gets the local ip address of the machine the UDP sender is being run on.
Private void OnApplicationQuit() Sent to all GameObjects before the application quits. Unity calls this message when play mode is stopped.
Private void SenderWork(IPAddress targetIP) Method run by the thread.
Public void SendPdu(AcknowledgePdu pdu) Method to send AcknowledgePDUs.
Public void SendPdu(ActionRequestPdu pdu) Method to send ActionRequestPDUs.
Public void SendPdu(ActionResponsePdu pdu) Method to send ActionResponsePDUs.
Public void SendPdu(CollisionPdu pdu) Method to send CollisionPDUs.
Public void SendPdu(CommentPdu pdu) Method to send CommentPDUs.
Public void SendPdu(CreateEntityPdu pdu) Method to send CreateEntityPDUs.
Public void SendPdu(DataPdu pdu) Method to send DataPDUs.
Public void SendPdu(DataQueryPdu pdu) Method to send DataQueryPDUs.
Public void SendPdu(DesignatorPdu pdu) Method to send DesignatorPDUs.
Public void SendPdu(DetonationPdu pdu) Method to send DetonationPDUs.
Public void SendPdu(ElectronicEmissionsPdu pdu) Method to send ElectronicEmissionsPDUs.
Public void SendPdu(EntityStatePdu pdu) Method to send EntityStatePDUs.
Public void SendPdu(EntityStateUpdatePdu pdu) Method to send EntityStateUpdatePDUs.
Public void SendPdu(EventReportPdu pdu) Method to send EventReportPDUs.
Public void SendPdu(FirePdu pdu) Method to send FirePDUs.
Public void SendPdu(ReceiverPdu pdu) Method to send ReceiverPDUs.
Public void SendPdu(RemoveEntityPdu pdu) Method to send RemoveEntityPDUs.
Public void SendPdu(RepairCompletePdu pdu) Method to send RepairCompletePDUs.
Public void SendPdu(RepairResponsePdu pdu) Method to send RepairResponsePDUs.
Public void SendPdu(ResupplyCancelPdu pdu) Method to send ResupplyCancelPDUs.
Public void SendPdu(ResupplyOfferPdu pdu) Method to send ResupplyOfferPDUs.
Public void SendPdu(ResupplyReceivedPdu pdu) Method to send ResupplyReceivedPDUs.
Public void SendPdu(ServiceRequestPdu pdu) Method to send ServiceRequestPDUs.
Public void SendPdu(SetDataPdu pdu) Method to send SetDataPDUs.
Public void SendPdu(SignalPdu pdu) Method to send SignalPDUs.
Public void SendPdu(StartResumePdu pdu) Method to send StartResumePDUs.
Public void SendPdu(StopFreezePdu pdu) Method to send StopFreezePDUs.
Public void SendPdu(TransmitterPdu pdu) Method to send TransmitterPDUs.
Public void Stop() Stops the thread and disconnects.

Back to Top


Details

AutoConnectAtStart

public bool autoConnectAtStart = true

Whether or not to auto connect the receive address on start.

Back to Top


ConnectionType

public EConnectionType connectionType

The type of connection used in sending out the PDUs.

Back to Top


DOS

private DataOutputStream dos = new DataOutputStream(Endian.Big)

The data stream that is used to convert PDUs to bytes prior to emitting them as 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


IPAddressString

public string ipAddressString = "0.0.0.0"

The IP Address to receive UDP packets from. An IP Address of 0.0.0.0 listens to all connection on the specified port.

Back to Top


MaxQueueSize

public int maxQueueSize = 1 * 1024

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

Back to Top


PDUs

private ConcurrentQueue<byte[]> pdus

The concurrent queue that houses all PDUs that are awaiting being sent on the network.

Back to Top


Port

public int port = 3000

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

Back to Top


Sending

private bool sending = true

Whether or not the PDU Sender is currently sending PDUs.

Back to Top


Thread

private Thread thread

The thread that is responsible for running the PDU Sender.

Back to Top


OnFailedToConnect

public UnityEvent<Exception> OnFailedToConnect

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

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

Back to Top


Awake

private void Awake()

Awake is called when the script instance is being loaded.

https://docs.unity3d.com/ScriptReference/MonoBehaviour.Awake.html

Back to Top


ChangeAddress

public void ChangeAddress
(
    string IP,
    int port
)

Changes the IP of the UDP Sender safely

Parameter Description
IP The new IP to change the UDP sender to.
port The new port to change the UDP sender to.

Back to Top


Init

public void Init()

Starts up the thread from the desired ip.

Back to Top


IsConnected

public bool IsConnected()

Gets whether or not the PDU Sender is currently connected.

Returns
Whether or not the PDU Sender is currently connected.

Back to Top


LocalIPAddress

private static IPAddress LocalIPAddress()

Gets the local ip address of the machine the UDP sender is being run on.

Returns
The local ip address of the machine the UDP sender is being run on.

Back to Top


OnApplicationQuit

private void OnApplicationQuit()

Sent to all GameObjects before the application quits. Unity calls this message when play mode is stopped.

https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnApplicationQuit.html

Back to Top


SenderWork

private void SenderWork
(
    IPAddress targetIP
)

Method run by the thread.

Parameter Description
targetIP The target IP to connect the UDP sender to if Unicast or Multicast is being used.

Back to Top


SendPdu

public void SendPdu
(
    AcknowledgePdu pdu
)

Method to send AcknowledgePDUs.

Parameter Description
pdu The AcknowledgePDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    ActionRequestPdu pdu
)

Method to send ActionRequestPDUs.

Parameter Description
pdu The ActionRequestPDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    ActionResponsePdu pdu
)

Method to send ActionResponsePDUs.

Parameter Description
pdu The ActionResponsePDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    CollisionPdu pdu
)

Method to send CollisionPDUs.

Parameter Description
pdu The CollisionPDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    CommentPdu pdu
)

Method to send CommentPDUs.

Parameter Description
pdu The CommentPDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    CreateEntityPdu pdu
)

Method to send CreateEntityPDUs.

Parameter Description
pdu The CreateEntityPDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    DataPdu pdu
)

Method to send DataPDUs.

Parameter Description
pdu The DataPDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    DataQueryPdu pdu
)

Method to send DataQueryPDUs.

Parameter Description
pdu The DataQueryPDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    DesignatorPdu pdu
)

Method to send DesignatorPDUs.

Parameter Description
pdu The DesignatorPDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    DetonationPdu pdu
)

Method to send DetonationPDUs.

Parameter Description
pdu The DetonationPDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    ElectronicEmissionsPdu pdu
)

Method to send ElectronicEmissionsPDUs.

Parameter Description
pdu The ElectronicEmissionsPDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    EntityStatePdu pdu
)

Method to send EntityStatePDUs.

Parameter Description
pdu The EntityStatePDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    EntityStateUpdatePdu pdu
)

Method to send EntityStateUpdatePDUs.

Parameter Description
pdu The EntityStateUpdatePDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    EventReportPdu pdu
)

Method to send EventReportPDUs.

Parameter Description
pdu The EventReportPDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    FirePdu pdu
)

Method to send FirePDUs.

Parameter Description
pdu The FirePDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    ReceiverPdu pdu
)

Method to send ReceiverPDUs.

Parameter Description
pdu The ReceiverPDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    RemoveEntityPdu pdu
)

Method to send RemoveEntityPDUs.

Parameter Description
pdu The RemoveEntityPDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    RepairCompletePdu pdu
)

Method to send RepairCompletePDUs.

Parameter Description
pdu The RepairCompletePDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    RepairResponsePdu pdu
)

Method to send RepairResponsePDUs.

Parameter Description
pdu The RepairResponsePDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    ResupplyCancelPdu pdu
)

Method to send ResupplyCancelPDUs.

Parameter Description
pdu The ResupplyCancelPDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    ResupplyOfferPdu pdu
)

Method to send ResupplyOfferPDUs.

Parameter Description
pdu The ResupplyOfferPDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    ResupplyReceivedPdu pdu
)

Method to send ResupplyReceivedPDUs.

Parameter Description
pdu The ResupplyReceivedPDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    ServiceRequestPdu pdu
)

Method to send ServiceRequestPDUs.

Parameter Description
pdu The ServiceRequestPDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    SetDataPdu pdu
)

Method to send SetDataPDUs.

Parameter Description
pdu The SetDataPDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    SignalPdu pdu
)

Method to send SignalPDUs.

Parameter Description
pdu The SignalPDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    StartResumePdu pdu
)

Method to send StartResumePDUs.

Parameter Description
pdu The StartResumePDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    StopFreezePdu pdu
)

Method to send StopFreezePDUs.

Parameter Description
pdu The StopFreezePDU to send out.

Back to Top


SendPdu

public void SendPdu
(
    TransmitterPdu pdu
)

Method to send TransmitterPDUs.

Parameter Description
pdu The TransmitterPDU to send out.

Back to Top


Stop

public void Stop()

Stops the thread and disconnects.

Back to Top