UdpClient.SendAsync Method (Byte, Int32)
Sends a UDP datagram asynchronously to a remote host.
Assembly: System (in System.dll)
[HostProtectionAttribute(SecurityAction.LinkDemand, ExternalThreading = true)] public Task<int> SendAsync( byte datagram, int bytes )
- Type: System.Byte
An array of type Byte that specifies the UDP datagram that you intend to send represented as an array of bytes.
- Type: System.Int32
The number of bytes in the datagram.
This overload sends datagrams to the remote host established in the Connect method. If you do not call Connect before calling this overload, the method will throw a SocketException. If you receive a SocketException, use SocketException.ErrorCode to obtain the specific error code. Once you have obtained this code, you can refer to the Windows Sockets version 2 API error code documentation in MSDN for a detailed description of the error.
If you want to send datagrams to a different remote host, you must call the Connect method and specify the desired remote host. Use either of the other SendAsync method overloads to send datagrams to a broadcast address.
The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: ExternalThreading. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.