Class UdpSocket
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
UdpSocket(IPAddress, int)
public UdpSocket(IPAddress bindAddress, int port)
Parameters
UdpSocket(IPEndPoint)
Initialize and bind a new UdpSocket.
public UdpSocket(IPEndPoint bindEndpoint)
Parameters
bindEndpoint
IPEndPointLocal 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
stringport
intaddressFamily
AddressFamily
Properties
AddressFamily
public AddressFamily AddressFamily { get; }
Property Value
Port
Gets the main bind port of the Socket.
public int Port { get; }
Property Value
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
stringaddressFamily
AddressFamily
Returns
Exceptions
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
CancellationTokenA 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
SocketAddressA SocketAddress instance that gets updated with the value of the remote peer when this method returns.
cancellationToken
CancellationTokenA 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
EndPointThe remote host to which to send the data.
cancellationToken
CancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
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
SocketAddressThe remote host to which to send the data.
cancellationToken
CancellationTokenA cancellation token that can be used to cancel the asynchronous operation.