Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Net.​Sockets.​UdpClient

Assembly: System.Net.Sockets

Inheritance: object → UdpClient

Implemented Interfaces

Provides User Datagram Protocol (UDP) network services.

Properties

protected bool
Active
Gets or sets a value indicating whether a default remote host has been established.
public int
Available
Gets the amount of data received from the network that is available to read.
public Socket
Client
Gets or sets the underlying network <see cref="T:System.Net.Sockets.Socket" /> .
public bool
DontFragment
Gets or sets a <see cref="T:System.Boolean" /> value that specifies whether the <see cref="T:System.Net.Sockets.UdpClient" /> allows Internet Protocol (IP) datagrams to be fragmented.
public bool
EnableBroadcast
Gets or sets a <see cref="T:System.Boolean" /> value that specifies whether the <see cref="T:System.Net.Sockets.UdpClient" /> may send broadcast packets.
public bool
ExclusiveAddressUse
Gets or sets a <see cref="T:System.Boolean" /> value that specifies whether the <see cref="T:System.Net.Sockets.UdpClient" /> allows only one client to use a port.
public bool
MulticastLoopback
Gets or sets a <see cref="T:System.Boolean" /> value that specifies whether outgoing multicast packets are delivered to the sending application.
public short
Ttl
Gets or sets a value that specifies the Time to Live (TTL) value of Internet Protocol (IP) packets sent by the <see cref="T:System.Net.Sockets.UdpClient" /> .

Methods

public void
AllowNatTraversal​(bool allowed)
Enables or disables Network Address Translation (NAT) traversal on a <see cref="T:System.Net.Sockets.UdpClient" /> instance.
allowed A Boolean value that specifies whether to enable or disable NAT traversal.
public IAsyncResult
BeginReceive​(AsyncCallback requestCallback, object state)
Receives a datagram from a remote host asynchronously.
Returns An <see cref="T:System.IAsyncResult" /> object that references the asynchronous receive.
requestCallback An <see cref="T:System.AsyncCallback" /> delegate that references the method to invoke when the operation is complete.
state A user-defined object that contains information about the receive operation. This object is passed to the <paramref name="requestCallback" /> delegate when the operation is complete.
public IAsyncResult
BeginSend​(byte[] datagram, int bytes, AsyncCallback? requestCallback, object state)
Sends a datagram to a remote host asynchronously. The destination was specified previously by a call to <see cref="Overload:System.Net.Sockets.UdpClient.Connect" /> .
Returns An <see cref="T:System.IAsyncResult" /> object that references the asynchronous send.
datagram A <see cref="T:System.Byte" /> array that contains the data to be sent.
bytes The number of bytes to send.
requestCallback An <see cref="T:System.AsyncCallback" /> delegate that references the method to invoke when the operation is complete.
state A user-defined object that contains information about the send operation. This object is passed to the <paramref name="requestCallback" /> delegate when the operation is complete.
public IAsyncResult
BeginSend​(byte[] datagram, int bytes, IPEndPoint endPoint, AsyncCallback requestCallback, object state)
Sends a datagram to a destination asynchronously. The destination is specified by a <see cref="T:System.Net.EndPoint" /> .
Returns An <see cref="T:System.IAsyncResult" /> object that references the asynchronous send.
datagram A <see cref="T:System.Byte" /> array that contains the data to be sent.
bytes The number of bytes to send.
endPoint The <see cref="T:System.Net.EndPoint" /> that represents the destination for the data.
requestCallback An <see cref="T:System.AsyncCallback" /> delegate that references the method to invoke when the operation is complete.
state A user-defined object that contains information about the send operation. This object is passed to the <paramref name="requestCallback" /> delegate when the operation is complete.
public IAsyncResult
BeginSend​(byte[] datagram, int bytes, string hostname, int port, AsyncCallback requestCallback, object state)
Sends a datagram to a destination asynchronously. The destination is specified by the host name and port number.
Returns An <see cref="T:System.IAsyncResult" /> object that references the asynchronous send.
datagram A <see cref="T:System.Byte" /> array that contains the data to be sent.
bytes The number of bytes to send.
hostname The destination host.
port The destination port number.
requestCallback An <see cref="T:System.AsyncCallback" /> delegate that references the method to invoke when the operation is complete.
state A user-defined object that contains information about the send operation. This object is passed to the <paramref name="requestCallback" /> delegate when the operation is complete.
public void
Close​()
Closes the UDP connection.
public void
Connect​(IPAddress addr, int port)
Establishes a default remote host using the specified IP address and port number.
addr The <see cref="T:System.Net.IPAddress" /> of the remote host to which you intend to send data.
port The port number to which you intend send data.
public void
Connect​(IPEndPoint endPoint)
Establishes a default remote host using the specified network endpoint.
endPoint An <see cref="T:System.Net.IPEndPoint" /> that specifies the network endpoint to which you intend to send data.
public void
Connect​(string hostname, int port)
Establishes a default remote host using the specified host name and port number.
hostname The DNS name of the remote host to which you intend send data.
port The port number on the remote host to which you intend to send data.
public void
Dispose​()
Releases the managed and unmanaged resources used by the <see cref="T:System.Net.Sockets.UdpClient" /> .
protected void
Dispose​(bool disposing)
Releases the unmanaged resources used by the <see cref="T:System.Net.Sockets.UdpClient" /> and optionally releases the managed resources.
disposing <see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.
public void
DropMulticastGroup​(IPAddress multicastAddr)
Leaves a multicast group.
multicastAddr The <see cref="T:System.Net.IPAddress" /> of the multicast group to leave.
public void
DropMulticastGroup​(IPAddress multicastAddr, int ifindex)
Leaves a multicast group.
multicastAddr The <see cref="T:System.Net.IPAddress" /> of the multicast group to leave.
ifindex The local address of the multicast group to leave.
public byte[]
EndReceive​(IAsyncResult asyncResult, IPEndPoint&? remoteEP)
public int
EndSend​(IAsyncResult asyncResult)
Ends a pending asynchronous send.
Returns If successful, the number of bytes sent to the <see cref="T:System.Net.Sockets.UdpClient" /> .
asyncResult An <see cref="T:System.IAsyncResult" /> object returned by a call to <see cref="Overload:System.Net.Sockets.UdpClient.BeginSend" /> .
public void
JoinMulticastGroup​(int ifindex, IPAddress multicastAddr)
Adds a <see cref="T:System.Net.Sockets.UdpClient" /> to a multicast group.
ifindex The interface index associated with the local IP address on which to join the multicast group.
multicastAddr The multicast <see cref="T:System.Net.IPAddress" /> of the group you want to join.
public void
JoinMulticastGroup​(IPAddress multicastAddr)
Adds a <see cref="T:System.Net.Sockets.UdpClient" /> to a multicast group.
multicastAddr The multicast <see cref="T:System.Net.IPAddress" /> of the group you want to join.
public void
JoinMulticastGroup​(IPAddress multicastAddr, int timeToLive)
Adds a <see cref="T:System.Net.Sockets.UdpClient" /> to a multicast group with the specified Time to Live (TTL).
multicastAddr The <see cref="T:System.Net.IPAddress" /> of the multicast group to join.
timeToLive The Time to Live (TTL), measured in router hops.
public void
JoinMulticastGroup​(IPAddress multicastAddr, IPAddress localAddress)
Adds a <see cref="T:System.Net.Sockets.UdpClient" /> to a multicast group.
multicastAddr The multicast <see cref="T:System.Net.IPAddress" /> of the group you want to join.
localAddress The local <see cref="T:System.Net.IPAddress" /> .
public byte[]
Receive​(IPEndPoint&? remoteEP)
ReceiveAsync​()
Returns a UDP datagram asynchronously that was sent by a remote host.
Returns The task object representing the asynchronous operation.
ReceiveAsync​(Threading.​CancellationToken cancellationToken)
Returns a UDP datagram asynchronously that was sent by a remote host.
Returns A <see cref="T:System.Threading.Tasks.ValueTask`1" /> representing the asynchronous operation.
cancellationToken The token to monitor for cancellation requests.
public int
Send​(byte[] dgram, int bytes)
Sends a UDP datagram to a remote host.
Returns The number of bytes sent.
dgram An array of type <see cref="T:System.Byte" /> that specifies the UDP datagram that you intend to send represented as an array of bytes.
bytes The number of bytes in the datagram.
public int
Send​(byte[] dgram, int bytes, IPEndPoint? endPoint)
Sends a UDP datagram to the host at the specified remote endpoint.
Returns The number of bytes sent.
dgram An array of type <see cref="T:System.Byte" /> that specifies the UDP datagram that you intend to send, represented as an array of bytes.
bytes The number of bytes in the datagram.
endPoint An <see cref="T:System.Net.IPEndPoint" /> that represents the host and port to which to send the datagram.
public int
Send​(byte[] dgram, int bytes, string hostname, int port)
Sends a UDP datagram to a specified port on a specified remote host.
Returns The number of bytes sent.
dgram An array of type <see cref="T:System.Byte" /> that specifies the UDP datagram that you intend to send represented as an array of bytes.
bytes The number of bytes in the datagram.
hostname The name of the remote host to which you intend to send the datagram.
port The remote port number with which you intend to communicate.
public int
Send​(ReadOnlySpan<​byte> datagram)
Sends a UDP datagram to a remote host.
Returns The number of bytes sent.
datagram An <see cref="T:System.ReadOnlySpan`1" /> of Type <see cref="T:System.Byte" /> that specifies the UDP datagram that you intend to send.
public int
Send​(ReadOnlySpan<​byte> datagram, IPEndPoint? endPoint)
Sends a UDP datagram to the host at the specified remote endpoint.
Returns The number of bytes sent.
datagram An <see cref="T:System.ReadOnlySpan`1" /> of Type <see cref="T:System.Byte" /> that specifies the UDP datagram that you intend to send.
endPoint An <see cref="T:System.Net.IPEndPoint" /> that represents the host and port to which to send the datagram.
public int
Send​(ReadOnlySpan<​byte> datagram, string hostname, int port)
Sends a UDP datagram to a specified port on a specified remote host.
Returns The number of bytes sent.
datagram An <see cref="T:System.ReadOnlySpan`1" /> of Type <see cref="T:System.Byte" /> that specifies the UDP datagram that you intend to send.
hostname The name of the remote host to which you intend to send the datagram.
port The remote port number with which you intend to communicate.
SendAsync​(byte[] datagram, int bytes)
Sends a UDP datagram asynchronously to a remote host.
Returns Returns <see cref="T:System.Threading.Tasks.Task`1" /> .
datagram An array of type <see cref="T:System.Byte" /> that specifies the UDP datagram that you intend to send represented as an array of bytes.
bytes The number of bytes in the datagram.
SendAsync​(byte[] datagram, int bytes, IPEndPoint? endPoint)
Sends a UDP datagram asynchronously to a remote host.
Returns Returns <see cref="T:System.Threading.Tasks.Task`1" /> .
datagram An array of type <see cref="T:System.Byte" /> that specifies the UDP datagram that you intend to send represented as an array of bytes.
bytes The number of bytes in the datagram.
endPoint An <see cref="T:System.Net.IPEndPoint" /> that represents the host and port to which to send the datagram.
SendAsync​(byte[] datagram, int bytes, string hostname, int port)
Sends a UDP datagram asynchronously to a remote host.
Returns Returns <see cref="T:System.Threading.Tasks.Task`1" /> .
datagram An array of type <see cref="T:System.Byte" /> that specifies the UDP datagram that you intend to send represented as an array of bytes.
bytes The number of bytes in the datagram.
hostname The name of the remote host to which you intend to send the datagram.
port The remote port number with which you intend to communicate.
SendAsync​(ReadOnlyMemory<​byte> datagram, IPEndPoint? endPoint, Threading.​CancellationToken cancellationToken = null)
Sends a UDP datagram asynchronously to a remote host.
Returns A <see cref="T:System.Threading.Tasks.ValueTask`1" /> that represents the asynchronous send operation. The value of its Result property contains the number of bytes sent.
datagram An <see cref="T:System.ReadOnlyMemory`1" /> of Type <see cref="T:System.Byte" /> that specifies the UDP datagram that you intend to send.
endPoint An <see cref="T:System.Net.IPEndPoint" /> that represents the host and port to which to send the datagram.
cancellationToken The token to monitor for cancellation requests. The default value is None.
SendAsync​(ReadOnlyMemory<​byte> datagram, string hostname, int port, Threading.​CancellationToken cancellationToken = null)
Sends a UDP datagram asynchronously to a remote host.
Returns A <see cref="T:System.Threading.Tasks.ValueTask`1" /> that represents the asynchronous send operation. The value of its Result property contains the number of bytes sent.
datagram An <see cref="T:System.ReadOnlyMemory`1" /> of Type <see cref="T:System.Byte" /> that specifies the UDP datagram that you intend to send.
hostname The name of the remote host to which you intend to send the datagram.
port The remote port number with which you intend to communicate.
cancellationToken The token to monitor for cancellation requests. The default value is None.
SendAsync​(ReadOnlyMemory<​byte> datagram, Threading.​CancellationToken cancellationToken = null)
Sends a UDP datagram asynchronously to a remote host.
Returns A <see cref="T:System.Threading.Tasks.ValueTask`1" /> that represents the asynchronous send operation. The value of its Result property contains the number of bytes sent.
datagram An <see cref="T:System.ReadOnlyMemory`1" /> of Type <see cref="T:System.Byte" /> that specifies the UDP datagram that you intend to send.
cancellationToken The token to monitor for cancellation requests. The default value is None.
public bool
Equals​(object obj)
Inherited from object
protected void
Finalize​()
Inherited from object
public int
GetHashCode​()
Inherited from object
public Type
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object
public string
ToString​()
Inherited from object