TcpListener Constructor (Int32)

NOTE: This API is now obsolete.

Initializes a new instance of the TcpListener class that listens on the specified port.

Namespace:  System.Net.Sockets
Assembly:  System (in System.dll)

public function TcpListener(
	port : int


Type: System.Int32

The port on which to listen for incoming connection attempts.


port is not between MinPort and MaxPort.

This constructor is obsolete. Use the TcpListener.TcpListener(IPAddress, Int32) or TcpListener.TcpListener(IPEndPoint) constructors.

This constructor allows you to specify the port number on which to listen for incoming connection attempts. With this constructor, the underlying service provider assigns the most appropriate network address. If you do not care which local port is used, you can specify 0 for the port number. In this case, the service provider will assign an available port number between 1024 and 5000. If you use this approach, you can discover what local network address and port number has been assigned by using the LocalEndpoint property.

Call the Start method to begin listening for incoming connection attempts.

The following code example creates a TcpListener using a local port number.

No code example is currently available or this language may not be supported.
//Creates an instance of the TcpListener class by providing a local port number.  
IPAddress* ipAddress = Dns::Resolve(S"localhost")->AddressList[0];
    TcpListener* tcpListener =  new TcpListener(ipAddress, 13);    
catch ( Exception* e ){
    Console::WriteLine( e->ToString());

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 1.0
Obsolete (compiler warning) in 3.5
Obsolete (compiler warning) in 3.5 SP1
Obsolete (compiler warning) in 3.0
Obsolete (compiler warning) in 3.0 SP1
Obsolete (compiler warning) in 3.0 SP2
Obsolete (compiler warning) in 2.0
Obsolete (compiler warning) in 2.0 SP1
Obsolete (compiler warning) in 2.0 SP2
Obsolete (compiler warning) in 1.1

.NET Compact Framework

Supported in: 1.0
Obsolete (compiler warning) in 3.5
Obsolete (compiler warning) in 2.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft