TcpListener Construtores
Definição
Inicializa uma nova instância da classe TcpListener.Initializes a new instance of the TcpListener class.
Sobrecargas
| TcpListener(Int32) |
Obsoleto.
Obsoleto.
Obsoleto.
Obsoleto.
Inicializa uma nova instância da classe TcpListener que escuta na porta especificada.Initializes a new instance of the TcpListener class that listens on the specified port. |
| TcpListener(IPEndPoint) |
Inicializa uma nova instância da classe TcpListener com o ponto de extremidade local especificado.Initializes a new instance of the TcpListener class with the specified local endpoint. |
| TcpListener(IPAddress, Int32) |
Inicializa uma nova instância da classe TcpListener que escuta tentativas de conexões de entrada no endereço IP local e no número da porta especificados.Initializes a new instance of the TcpListener class that listens for incoming connection attempts on the specified local IP address and port number. |
TcpListener(Int32)
Cuidado
This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead. https://go.microsoft.com/fwlink/?linkid=14202
Cuidado
This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead. http://go.microsoft.com/fwlink/?linkid=14202
Cuidado
Use TcpListener(IPAddress localaddr, int port).
Cuidado
Use TcpListener (IPAddress address, int port) instead
Inicializa uma nova instância da classe TcpListener que escuta na porta especificada.Initializes a new instance of the TcpListener class that listens on the specified port.
public:
TcpListener(int port);
[System.Obsolete("This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead. https://go.microsoft.com/fwlink/?linkid=14202")]
public TcpListener (int port);
public TcpListener (int port);
[System.Obsolete("This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public TcpListener (int port);
[System.Obsolete("Use TcpListener(IPAddress localaddr, int port).")]
public TcpListener (int port);
[System.Obsolete("Use TcpListener (IPAddress address, int port) instead")]
public TcpListener (int port);
[<System.Obsolete("This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead. https://go.microsoft.com/fwlink/?linkid=14202")>]
new System.Net.Sockets.TcpListener : int -> System.Net.Sockets.TcpListener
new System.Net.Sockets.TcpListener : int -> System.Net.Sockets.TcpListener
[<System.Obsolete("This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead. http://go.microsoft.com/fwlink/?linkid=14202")>]
new System.Net.Sockets.TcpListener : int -> System.Net.Sockets.TcpListener
[<System.Obsolete("Use TcpListener(IPAddress localaddr, int port).")>]
new System.Net.Sockets.TcpListener : int -> System.Net.Sockets.TcpListener
[<System.Obsolete("Use TcpListener (IPAddress address, int port) instead")>]
new System.Net.Sockets.TcpListener : int -> System.Net.Sockets.TcpListener
Public Sub New (port As Integer)
Parâmetros
- port
- Int32
A porta na qual escutar tentativas de conexão de entrada.The port on which to listen for incoming connection attempts.
- Atributos
Exceções
Exemplos
O exemplo de código a seguir cria um TcpListener usando um número de porta local.The following code example creates a TcpListener using a local port number.
//Creates an instance of the TcpListener class by providing a local port number.
IPAddress^ ipAddress = Dns::Resolve( "localhost" )->AddressList[ 0 ];
try
{
TcpListener^ tcpListener = gcnew TcpListener( ipAddress,13 );
}
catch ( Exception^ e )
{
Console::WriteLine( e->ToString() );
}
//Creates an instance of the TcpListener class by providing a local port number.
IPAddress ipAddress = Dns.Resolve("localhost").AddressList[0];
try{
TcpListener tcpListener = new TcpListener(ipAddress, 13);
}
catch ( Exception e ){
Console.WriteLine( e.ToString());
}
'Creates an instance of the TcpListener class by providing a local 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
Comentários
Esse construtor é obsoleto.This constructor is obsolete. Use os TcpListener.TcpListener(IPAddress, Int32) TcpListener.TcpListener(IPEndPoint) construtores ou.Use the TcpListener.TcpListener(IPAddress, Int32) or TcpListener.TcpListener(IPEndPoint) constructors.
Esse construtor permite que você especifique o número da porta na qual escuta as tentativas de conexão de entrada.This constructor allows you to specify the port number on which to listen for incoming connection attempts. Com esse construtor, o provedor de serviços subjacente atribui o endereço de rede mais apropriado.With this constructor, the underlying service provider assigns the most appropriate network address. Se você não se importa com qual porta local é usada, você pode especificar 0 para o número da porta.If you do not care which local port is used, you can specify 0 for the port number. Nesse caso, o provedor de serviços atribuirá um número de porta efêmera disponível.In this case, the service provider will assign an available ephemeral port number. Se você usar essa abordagem, poderá descobrir qual endereço de rede local e número de porta foi atribuído usando a LocalEndpoint propriedade.If you use this approach, you can discover what local network address and port number has been assigned by using the LocalEndpoint property.
Chame o Start método para começar a escutar as tentativas de conexão de entrada.Call the Start method to begin listening for incoming connection attempts.
Confira também
Aplica-se a
TcpListener(IPEndPoint)
Inicializa uma nova instância da classe TcpListener com o ponto de extremidade local especificado.Initializes a new instance of the TcpListener class with the specified local endpoint.
public:
TcpListener(System::Net::IPEndPoint ^ localEP);
public TcpListener (System.Net.IPEndPoint localEP);
new System.Net.Sockets.TcpListener : System.Net.IPEndPoint -> System.Net.Sockets.TcpListener
Public Sub New (localEP As IPEndPoint)
Parâmetros
- localEP
- IPEndPoint
Um IPEndPoint que representa o ponto de extremidade local ao qual o ouvinte Socket será associado.An IPEndPoint that represents the local endpoint to which to bind the listener Socket.
Exceções
localEP é null.localEP is null.
Exemplos
O exemplo de código a seguir cria uma instância da TcpListener classe usando o ponto de extremidade local.The following code example creates an instance of the TcpListener class using the local endpoint.
//Creates an instance of the TcpListener class by providing a local endpoint.
IPAddress^ ipAddress = Dns::Resolve( Dns::GetHostName() )->AddressList[ 0 ];
IPEndPoint^ ipLocalEndPoint = gcnew IPEndPoint( ipAddress,11000 );
try
{
TcpListener^ tcpListener = gcnew TcpListener( ipLocalEndPoint );
}
catch ( Exception^ e )
{
Console::WriteLine( e->ToString() );
}
//Creates an instance of the TcpListener class by providing a local endpoint.
IPAddress ipAddress = Dns.Resolve(Dns.GetHostName()).AddressList[0];
IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, 11000);
try{
TcpListener tcpListener = new TcpListener(ipLocalEndPoint);
}
catch ( Exception e ){
Console.WriteLine( e.ToString());
}
'Creates an instance of the TcpListener class by providing a local endpoint.
Dim ipAddress As IPAddress = Dns.Resolve(Dns.GetHostName()).AddressList(0)
Dim ipLocalEndPoint As New IPEndPoint(ipAddress, 11000)
Try
Dim tcpListener As New TcpListener(ipLocalEndPoint)
Catch e As Exception
Console.WriteLine(e.ToString())
End Try
Comentários
Esse construtor permite que você especifique o endereço IP local e o número da porta no qual as tentativas de conexão de entrada são escutadas.This constructor allows you to specify the local IP address and port number on which to listen for incoming connection attempts. Antes de usar esse construtor, você deve criar um IPEndPoint usando o número de porta e o endereço IP local desejado.Before using this constructor, you must create an IPEndPoint using the desired local IP address and port number. Passe isso IPEndPoint para o construtor como o localEP parâmetro.Pass this IPEndPoint to the constructor as the localEP parameter.
Se você não se importa com qual endereço local é atribuído, você pode criar um IPEndPoint usando IPAddress.Any como o parâmetro de endereço, e o provedor de serviços subjacente atribuirá o endereço de rede mais apropriado.If you do not care which local address is assigned, you can create an IPEndPoint using IPAddress.Any as the address parameter, and the underlying service provider will assign the most appropriate network address. Isso pode ajudar a simplificar seu aplicativo se você tiver várias interfaces de rede.This might help simplify your application if you have multiple network interfaces. Se você não se importa com qual porta local é usada, você pode criar um IPEndPoint usando 0 para o número da porta.If you do not care which local port is used, you can create an IPEndPoint using 0 for the port number. Nesse caso, o provedor de serviços atribuirá um número de porta efêmera disponível.In this case, the service provider will assign an available ephemeral port number. Se você usar essa abordagem, poderá descobrir qual endereço de rede local e número de porta foi atribuído usando a LocalEndpoint propriedade.If you use this approach, you can discover what local network address and port number has been assigned by using the LocalEndpoint property.
Chame o Start método para começar a escutar as tentativas de conexão de entrada.Call the Start method to begin listening for incoming connection attempts.
Observação
Esse membro emite o rastreamento de informações quando você ativa o rastreamento de rede em seu aplicativo.This member outputs trace information when you enable network tracing in your application. Para obter mais informações, consulte rastreamento de rede na .NET Framework.For more information, see Network Tracing in the .NET Framework.
Confira também
Aplica-se a
TcpListener(IPAddress, Int32)
Inicializa uma nova instância da classe TcpListener que escuta tentativas de conexões de entrada no endereço IP local e no número da porta especificados.Initializes a new instance of the TcpListener class that listens for incoming connection attempts on the specified local IP address and port number.
public:
TcpListener(System::Net::IPAddress ^ localaddr, int port);
public TcpListener (System.Net.IPAddress localaddr, int port);
new System.Net.Sockets.TcpListener : System.Net.IPAddress * int -> System.Net.Sockets.TcpListener
Public Sub New (localaddr As IPAddress, port As Integer)
Parâmetros
- localaddr
- IPAddress
Um IPAddress que representa o endereço IP local.An IPAddress that represents the local IP address.
- port
- Int32
A porta na qual escutar tentativas de conexão de entrada.The port on which to listen for incoming connection attempts.
Exceções
localaddr é null.localaddr is null.
Exemplos
O exemplo de código a seguir cria uma instância da TcpListener classe usando um endereço IP local e um número de porta.The following code example creates an instance of the TcpListener class using a local IP address and port number.
//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 = gcnew TcpListener( ipAddress,13 );
}
catch ( Exception^ e )
{
Console::WriteLine( e->ToString() );
}
//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());
}
'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
Comentários
Esse construtor permite que você especifique o endereço IP local e o número da porta no qual as tentativas de conexão de entrada são escutadas.This constructor allows you to specify the local IP address and port number on which to listen for incoming connection attempts. Antes de chamar este construtor, você deve primeiro criar um IPAddress usando o endereço local desejado.Before calling this constructor you must first create an IPAddress using the desired local address. Passe isso IPAddress para o construtor como o localaddr parâmetro.Pass this IPAddress to the constructor as the localaddr parameter. Se você não se importa com qual endereço local é atribuído, especifique IPAddress.Any para o localaddr parâmetro e o provedor de serviços subjacente atribuirá o endereço de rede mais apropriado.If you do not care which local address is assigned, specify IPAddress.Any for the localaddr parameter, and the underlying service provider will assign the most appropriate network address. Isso pode ajudar a simplificar seu aplicativo se você tiver várias interfaces de rede.This might help simplify your application if you have multiple network interfaces. Se você não se importa com qual porta local é usada, você pode especificar 0 para o número da porta.If you do not care which local port is used, you can specify 0 for the port number. Nesse caso, o provedor de serviços atribuirá um número de porta disponível entre 1024 e 65535.In this case, the service provider will assign an available port number between 1024 and 65535. Se você usar essa abordagem, poderá descobrir qual endereço de rede local e número de porta foi atribuído usando a LocalEndpoint propriedade.If you use this approach, you can discover what local network address and port number has been assigned by using the LocalEndpoint property.
Chame o Start método para começar a escutar as tentativas de conexão de entrada.Call the Start method to begin listening for incoming connection attempts.
Observação
Esse membro emite o rastreamento de informações quando você ativa o rastreamento de rede em seu aplicativo.This member outputs trace information when you enable network tracing in your application. Para obter mais informações, consulte rastreamento de rede na .NET Framework.For more information, see Network Tracing in the .NET Framework.