This documentation is archived and is not being maintained.

UdpClient.Send Method

Sends a UDP datagram to a remote host.

Overload List

Sends a UDP datagram to a remote host.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Send(Byte(), Integer) As Integer
[C#] public int Send(byte[], int);
[C++] public: int Send(unsigned char __gc[], int);
[JScript] public function Send(Byte[], int) : int;

Sends a UDP datagram to the host at the specified remote endpoint.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Send(Byte(), Integer, IPEndPoint) As Integer
[C#] public int Send(byte[], int, IPEndPoint);
[C++] public: int Send(unsigned char __gc[], int, IPEndPoint*);
[JScript] public function Send(Byte[], int, IPEndPoint) : int;

Sends a UDP datagram to a specified port on a specified remote host.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Send(Byte(), Integer, String, Integer) As Integer
[C#] public int Send(byte[], int, string, int);
[C++] public: int Send(unsigned char __gc[], int, String*, int);
[JScript] public function Send(Byte[], int, String, int) : int;

Example

[Visual Basic, C#, C++] The following example demonstrates the Send method. This example uses a host name and a port number to identify the target host.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of Send. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Dim udpClient As New UdpClient()

Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there")
Try
   udpClient.Send(sendBytes, sendBytes.Length, "www.contoso.com", 11000)
Catch e As Exception
   Console.WriteLine(e.ToString())
End Try

[C#] 
UdpClient udpClient = new UdpClient();

Byte[] sendBytes = Encoding.ASCII.GetBytes("Is anybody there");
try{
    udpClient.Send(sendBytes, sendBytes.Length, "www.contoso.com", 11000);
}
catch ( Exception e ){
    Console.WriteLine(e.ToString());    
}

[C++] 
UdpClient* udpClient = new UdpClient();

Byte sendBytes[] = Encoding::ASCII->GetBytes(S"Is anybody there");
try{
    udpClient->Send(sendBytes, sendBytes->Length, S"www.contoso.com", 11000);
}
catch ( Exception* e ){
    Console::WriteLine(e->ToString());    
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

UdpClient Class | UdpClient Members | System.Net.Sockets Namespace

Show: