TcpListener Constructor (Int32)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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)

[<ObsoleteAttribute("This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead.")>]
new : 
        port:int -> TcpListener


Type: System.Int32

The port on which to listen for incoming connection attempts.

Exception Condition

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.

.NET Framework
Available since 1.1
Return to top