FAST SDK Coding Reference 1.0.3
Loading...
Searching...
No Matches
UdpConnection Class Reference

Provides methods to communicate over User Datagram Protocol (UDP). More...

Public Member Functions

bool Open ()
 Opens a UDP connection.
 
void Send (byte[] data)
 Sends a datagram to FAST.UdpConnection.remoteIpAddress on FAST.UdpConnection.remotePort.
 

Public Attributes

string id
 Settings, Inspector, Code
Identifies this instance.
 
bool isLogging = true
 Inspector, Code
Set to true if all UDP activity should be logged to the Editor Console or Player log.
 
int localReceivePort = 60000
 Settings, Inspector, Code
The port of the local computer to recieve data on.
 
int localSendPort = 60001
 Settings, Inspector, Code
The port of the local computer to send data from.
 
UnityAction< byte[]> onDataReceivedEvent
 Inspector, Code
Calls the function(s) subscribed to this UnityAction when a datagram is received.
 
string remoteIpAddress = "0.0.0.0"
 Settings, Inspector, Code
The IP address of the remote computer to communicate with.
 
int remotePort = 50000
 Settings, Inspector, Code
The port of the remote computer to send data to.
 

Properties

List< byte[]> Data [get]
 Gets the list of datagrams recieved since the last read.
 

Private Attributes

bool isEnableBroadcast = true
 Inspector
Set to true if UDP messages should be broadcast to a subnet.
 
bool isOverwrite = false
 Inspector
Set to true if incoming the datagram should overwrite the previous datagram. Otherwise the datagram will added to FAST.UdpConnection.Data in the order it is recieved.
 

Detailed Description

Provides methods to communicate over User Datagram Protocol (UDP).

Receiving data is threaded for high-performance.

See also
System.Net.Sockets.UdpClient
System.Threading.Thread

Member Function Documentation

◆ Open()

bool Open ( )

Opens a UDP connection.

The connection is initialized by binding the local send and receive ports. Also, a Thread is started if one doesn't exist.

Returns
true if successful, else false
Note
Instead of calling Open() and configuring a FAST.UdpConnection yourself, FAST.UdpConnectionLoader and FAST.UdpConnectionSettings should be used to open a UDP connection with settings from file during the application load screen.

◆ Send()

void Send ( byte[] data)

Sends a datagram to FAST.UdpConnection.remoteIpAddress on FAST.UdpConnection.remotePort.

Parameters
dataThe datagram to send.

Member Data Documentation

◆ id

string id

Settings, Inspector, Code
Identifies this instance.

Loaded from FAST.UdpConnectionSettings at runtime.

◆ isEnableBroadcast

bool isEnableBroadcast = true
private

Inspector
Set to true if UDP messages should be broadcast to a subnet.

This functions the same as UdpClient.EnableBroadcast.

◆ isLogging

bool isLogging = true

Inspector, Code
Set to true if all UDP activity should be logged to the Editor Console or Player log.

Recieved messages are not logged because the communication may be too frequent.

◆ isOverwrite

bool isOverwrite = false
private

Inspector
Set to true if incoming the datagram should overwrite the previous datagram. Otherwise the datagram will added to FAST.UdpConnection.Data in the order it is recieved.

◆ localReceivePort

int localReceivePort = 60000

Settings, Inspector, Code
The port of the local computer to recieve data on.

Loaded from FAST.UdpConnectionSettings at runtime.

◆ localSendPort

int localSendPort = 60001

Settings, Inspector, Code
The port of the local computer to send data from.

Loaded from FAST.UdpConnectionSettings at runtime.

◆ onDataReceivedEvent

UnityAction<byte[]> onDataReceivedEvent

Inspector, Code
Calls the function(s) subscribed to this UnityAction when a datagram is received.

Warning
Use with caution if communication might be frequent. FAST.UdpConnection receives data on a separate thread, but these callbacks execute on Unity's main thread. Use FAST.UdpConnection.isOverwrite to only invoke this event on the most recent datagram received.

◆ remoteIpAddress

string remoteIpAddress = "0.0.0.0"

Settings, Inspector, Code
The IP address of the remote computer to communicate with.

Loaded from FAST.UdpConnectionSettings at runtime.

◆ remotePort

int remotePort = 50000

Settings, Inspector, Code
The port of the remote computer to send data to.

Loaded from FAST.UdpConnectionSettings at runtime.

Property Documentation

◆ Data

List<byte[]> Data
get

Gets the list of datagrams recieved since the last read.

The list of datagrams is ordered from oldest to newest. If FAST.UdpConnection.isOverwrite is true, the list only has 1 element.
After reading, the list is cleared from FAST.UdpConnection.


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