Table of Contents

Class UdpSocket

Namespace
Backdash.Network.Client
Assembly
Backdash.dll

UDP specialized socket interface.

public sealed class UdpSocket : IPeerSocket, IDisposable
Inheritance
UdpSocket
Implements
Inherited Members

Constructors

UdpSocket(int, bool)

public UdpSocket(int port, bool useIPv6 = false)

Parameters

port int
useIPv6 bool

UdpSocket(IPAddress, int)

public UdpSocket(IPAddress bindAddress, int port)

Parameters

bindAddress IPAddress
port int

UdpSocket(IPEndPoint)

Initialize and bind a new UdpSocket.

public UdpSocket(IPEndPoint bindEndpoint)

Parameters

bindEndpoint IPEndPoint

Local socket binding.

Exceptions

NetcodeException

Throws if the AddressFamily of IPAddress in bindEndpoint is not InterNetwork or InterNetworkV6>

UdpSocket(string, int, AddressFamily)

public UdpSocket(string bindHost, int port, AddressFamily addressFamily = AddressFamily.InterNetwork)

Parameters

bindHost string
port int
addressFamily AddressFamily

Properties

AddressFamily

public AddressFamily AddressFamily { get; }

Property Value

AddressFamily

Port

Gets the main bind port of the Socket.

public int Port { get; }

Property Value

int

Methods

Close()

public void Close()

Dispose()

public void Dispose()

GetDnsIpAddress(string, AddressFamily)

Returns the Internet Protocol (IP) addresses for the specified host and AddressFamily.

public static IPAddress GetDnsIpAddress(string host, AddressFamily addressFamily = AddressFamily.InterNetwork)

Parameters

host string
addressFamily AddressFamily

Returns

IPAddress

Exceptions

NetcodeException

ReceiveAsync(Memory<byte>, CancellationToken)

Receives data and returns the endpoint of the sending host.

public ValueTask<SocketReceiveFromResult> ReceiveAsync(Memory<byte> buffer, CancellationToken cancellationToken)

Parameters

buffer Memory<byte>

The buffer for the received data.

cancellationToken CancellationToken

A cancellation token that can be used to signal the asynchronous operation should be canceled.

Returns

ValueTask<SocketReceiveFromResult>

An asynchronous task that completes with a SocketReceiveFromResult containing the number of bytes received and the endpoint of the sending host.

ReceiveFromAsync(Memory<byte>, SocketAddress, CancellationToken)

Receives a datagram into the data buffer, using the specified SocketFlags, and stores the endpoint.

public ValueTask<int> ReceiveFromAsync(Memory<byte> buffer, SocketAddress address, CancellationToken cancellationToken)

Parameters

buffer Memory<byte>

The buffer for the received data.

address SocketAddress

A SocketAddress instance that gets updated with the value of the remote peer when this method returns.

cancellationToken CancellationToken

A cancellation token that can be used to signal the asynchronous operation should be canceled.

Returns

ValueTask<int>

An asynchronous task that completes with a SocketReceiveFromResult containing the number of bytes received and the endpoint of the sending host.

SendToAsync(ReadOnlyMemory<byte>, EndPoint, CancellationToken)

Sends data to the specified remote host.

public ValueTask<int> SendToAsync(ReadOnlyMemory<byte> buffer, EndPoint remoteEndPoint, CancellationToken cancellationToken)

Parameters

buffer ReadOnlyMemory<byte>

The buffer for the data to send.

remoteEndPoint EndPoint

The remote host to which to send the data.

cancellationToken CancellationToken

A cancellation token that can be used to cancel the asynchronous operation.

Returns

ValueTask<int>

An asynchronous task that completes with the number of bytes sent.

SendToAsync(ReadOnlyMemory<byte>, SocketAddress, CancellationToken)

Sends data to the specified remote host.

public ValueTask<int> SendToAsync(ReadOnlyMemory<byte> buffer, SocketAddress socketAddress, CancellationToken cancellationToken)

Parameters

buffer ReadOnlyMemory<byte>

The buffer for the data to send.

socketAddress SocketAddress

The remote host to which to send the data.

cancellationToken CancellationToken

A cancellation token that can be used to cancel the asynchronous operation.

Returns

ValueTask<int>

An asynchronous task that completes with the number of bytes sent.