This documentation is archived and is not being maintained.

TcpListener Constructor

.NET Framework 1.1

Initializes a new instance of the TcpListener class.

Overload List

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

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(Integer)
[C#] public TcpListener(int);
[C++] public: TcpListener(int);
[JScript] public function TcpListener(int);

Initializes a new instance of the TcpListener class with the specified local endpoint.

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(IPEndPoint)
[C#] public TcpListener(IPEndPoint);
[C++] public: TcpListener(IPEndPoint*);
[JScript] public function TcpListener(IPEndPoint);

Initializes a new instance of the TcpListener class that listens for incoming connection attempts on the specified local IP address and port number.

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(IPAddress, Integer)
[C#] public TcpListener(IPAddress, int);
[C++] public: TcpListener(IPAddress*, int);
[JScript] public function TcpListener(IPAddress, int);

Example

[Visual Basic, C#, C++] The following example creates an instance of the TcpListener class using a local IP address and port number.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of the TcpListener constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
'Creates an instance of the TcpListener class by providing a local IP address and port number.
Dim ipAddress As IPAddress = Dns.Resolve("localhost").AddressList(0)

Try
   Dim tcpListener As New TcpListener(ipAddress, 13)
Catch e As Exception
   Console.WriteLine(e.ToString())
End Try
         

[C#] 
//Creates an instance of the TcpListener class by providing a local IP address and port number.

IPAddress ipAddress = Dns.Resolve("localhost").AddressList[0];

try{
    TcpListener tcpListener =  new TcpListener(ipAddress, 13);    
}
catch ( Exception e){
    Console.WriteLine( e.ToString());
}
    

[C++] 
//Creates an instance of the TcpListener class by providing a local IP address and port number.

IPAddress* ipAddress = Dns::Resolve(S"localhost")->AddressList[0];

try{
    TcpListener* tcpListener =  new TcpListener(ipAddress, 13);    
}
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

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

Show: