Class UdpClient
Used to manage the UDP connection to a client.
Implements
Inherited Members
Namespace: Cosmos.System.Network.IPv4.UDP
Assembly: Cosmos.System2.dll
Syntax
public class UdpClient : IDisposable
Constructors
| Improve this Doc View SourceUdpClient()
Initializes a new instance of the UdpClient class.
Declaration
public UdpClient()
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown on fatal error. |
System.ArgumentException | Thrown if UdpClient with localPort 0 exists. |
UdpClient(Address, Int32)
Initializes a new instance of the UdpClient class.
Declaration
public UdpClient(Address dest, int destPort)
Parameters
Type | Name | Description |
---|---|---|
Address | dest | Destination address. |
System.Int32 | destPort | Destination port. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown on fatal error. |
System.ArgumentException | Thrown if UdpClient with localPort 0 exists. |
UdpClient(Int32)
Initializes a new instance of the UdpClient class.
Declaration
public UdpClient(int localPort)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | localPort | Local port. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown on fatal error. |
System.ArgumentException | Thrown if localPort already exists. |
Fields
| Improve this Doc View SourceDynamicPortStart
Declaration
public static ushort DynamicPortStart
Field Value
Type | Description |
---|---|
System.UInt16 |
Methods
| Improve this Doc View SourceClose()
Closes the active connection.
Declaration
public void Close()
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown on fatal error. |
Connect(Address, Int32)
Connects to the given client.
Declaration
public void Connect(Address dest, int destPort)
Parameters
Type | Name | Description |
---|---|---|
Address | dest | The destination address. |
System.Int32 | destPort | The destination port. |
Dispose()
Declaration
public void Dispose()
GetDynamicPort(Int32)
gets a random port
Declaration
public static ushort GetDynamicPort(int tries = 10)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | tries |
Returns
Type | Description |
---|---|
System.UInt16 |
NonBlockingReceive(ref EndPoint)
Receives data from the given end-point.
Declaration
public byte[] NonBlockingReceive(ref EndPoint source)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | source | The source end point. |
Returns
Type | Description |
---|---|
System.Byte[] |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown on fatal error. |
Receive(ref EndPoint)
Receives data from the given end-point.
Declaration
public byte[] Receive(ref EndPoint source)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | source | The source end point. |
Returns
Type | Description |
---|---|
System.Byte[] |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown on fatal error. |
Send(Byte[])
Sends data to the client.
Declaration
public void Send(byte[] data)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | The data to send. |
Exceptions
Type | Condition |
---|---|
System.Exception | Thrown if destination is null or destinationPort is 0. |
System.ArgumentException | Thrown on fatal error. |
System.OverflowException | Thrown if data array length is greater than Int32.MaxValue. |
System.IO.IOException | Thrown on IO error. |
Send(Byte[], Address, Int32)
Sends data to a remote host.
Declaration
public void Send(byte[] data, Address dest, int destPort)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | The data to send. |
Address | dest | The destination address. |
System.Int32 | destPort | The destination port. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown on fatal error. |
System.OverflowException | Thrown if data array length is greater than Int32.MaxValue. |
System.IO.IOException | Thrown on IO error. |