System.Net.Sockets.UdpClient.Send Method

Sends a UDP datagram to a remote host.

Syntax

public int Send (byte[] dgram, int bytes)

Parameters

dgram
An array of type 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.

Returns

The number of bytes sent.

Remarks

This overload sends datagrams to the remote host established in the UdpClient.Connect(string, int) method and returns the number of bytes sent. If you do not call UdpClient.Connect(string, int) before calling this overload, the UdpClient.Send(Byte[], int, System.Net.IPEndPoint) method will throw a System.Net.Sockets.SocketException. If you receive a System.Net.Sockets.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 UdpClient.Connect(string, int) method and specify the desired remote host. Use either of the other UdpClient.Send(Byte[], int, System.Net.IPEndPoint) method overloads to send datagrams to a broadcast address.

Requirements

Namespace: System.Net.Sockets
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0