This topic has not yet been rated - Rate this topic

UdpClient Constructor (Int32)

Initializes a new instance of the UdpClient class and binds it to the local port number provided.

Namespace:  System.Net.Sockets
Assembly:  System (in System.dll)
public UdpClient(
	int port


Type: System.Int32
The local port number from which you intend to communicate.

The port parameter is greater than MaxPort or less than MinPort.


An error occurred when accessing the socket. See the Remarks section for more information.

This constructor creates an underlying Socket and binds it to the port number from which you intend to communicate. Use this constructor if you are only interested in setting the local port number. The underlying service provider will assign the local IP address. If you pass 0 to the constructor, the underlying service provider will assign a port number.


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.

This constructor works only with IPv4 address types.

The following example demonstrates using a local port number to create an instance of the UdpClient class.

//Creates an instance of the UdpClient class to listen on
// the default interface using a particular port.
         UdpClient udpClient = new UdpClient(11000);
catch (Exception e ) {

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.