TcpListener.LocalEndpoint TcpListener.LocalEndpoint TcpListener.LocalEndpoint TcpListener.LocalEndpoint Property

Définition

Obtient le EndPoint sous-jacent du TcpListener actuel.Gets the underlying EndPoint of the current TcpListener.

public:
 property System::Net::EndPoint ^ LocalEndpoint { System::Net::EndPoint ^ get(); };
public System.Net.EndPoint LocalEndpoint { get; }
member this.LocalEndpoint : System.Net.EndPoint
Public ReadOnly Property LocalEndpoint As EndPoint

Valeur de propriété

EndPoint auquel Socket est lié.The EndPoint to which the Socket is bound.

Exemples

L’exemple de code suivant affiche le numéro d’adresse et le port IP local sur lequel le TcpListener écoute les demandes de connexion entrantes.The following code example displays the local IP address and port number on which the TcpListener is listening for incoming connection requests.

try
{
   // Use the Pending method to poll the underlying socket instance for client connection requests.
   TcpListener^ tcpListener = gcnew TcpListener( portNumber );
   tcpListener->Start();

   if ( !tcpListener->Pending() )
   {
      Console::WriteLine( "Sorry, no connection requests have arrived" );
   }
   else
   {
      //Accept the pending client connection and return a TcpClient object^ initialized for communication.
      TcpClient^ tcpClient = tcpListener->AcceptTcpClient();
      
      // Using the RemoteEndPoint property.
      Console::WriteLine( "I am listening for connections on {0} on port number {1}",
         IPAddress::Parse( ( (IPEndPoint^)(tcpListener->LocalEndpoint) )->Address->ToString() ),
         ( (IPEndPoint^)(tcpListener->LocalEndpoint) )->Port );
        
try{
        // Use the Pending method to poll the underlying socket instance for client connection requests.
IPAddress ipAddress = Dns.Resolve("localhost").AddressList[0];
     	TcpListener tcpListener =  new TcpListener(ipAddress, portNumber); 
     	tcpListener.Start();
     	
	if (!tcpListener.Pending()) {

	Console.WriteLine("Sorry, no connection requests have arrived");
	
 }
 else{

             //Accept the pending client connection and return a TcpClient object initialized for communication.
             TcpClient tcpClient = tcpListener.AcceptTcpClient();
             // Using the RemoteEndPoint property.
             Console.WriteLine("I am listening for connections on " + 
                                         IPAddress.Parse(((IPEndPoint)tcpListener.LocalEndpoint).Address.ToString()) +
	                                        "on port number " + ((IPEndPoint)tcpListener.LocalEndpoint).Port.ToString());


Try

	 Dim ipAddress As IPAddress = Dns.Resolve("localhost").AddressList(0)
  Dim tcpListener As New TcpListener(ipAddress, portNumber)
  tcpListener.Start()
  
   ' Use the Pending method to poll the underlying socket instance for client connection requests.
   If Not tcpListener.Pending() Then
      
      Console.WriteLine("Sorry, no connection requests have arrived")
   
   Else
      
      'Accept the pending client connection and return a TcpClient object initialized for communication.
      Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient()
      ' Using the RemoteEndPoint property.
      Console.Write("I am listening for connections on ")
      Console.Writeline(IPAddress.Parse(CType(tcpListener.LocalEndpoint, IPEndPoint).Address.ToString())) 
      Console.Write("on port number ")
      Console.Write(CType(tcpListener.LocalEndpoint, IPEndPoint).Port.ToString())
      

Remarques

Vous pouvez utiliser le LocalEndpoint propriété pour identifier le réseau local interface et numéro de port utilisé pour écouter les demandes entrantes des clients, une fois une connexion de socket a été établie.You can use the LocalEndpoint property to identify the local network interface and port number being used to listen for incoming client connection requests, after a socket connection has been made. Vous devez tout d’abord effectuer un cast EndPoint à un IPEndPoint.You must first cast this EndPoint to an IPEndPoint. Vous pouvez ensuite appeler la IPEndPoint.Address propriété à récupérer l’adresse IP locale et le IPEndPoint.Port propriété à récupérer le numéro de port local.You can then call the IPEndPoint.Address property to retrieve the local IP address, and the IPEndPoint.Port property to retrieve the local port number.

S’applique à

Voir aussi