Determines if there are pending connection requests.
Assembly: System (in System.dll)
This non-blocking method determines if there are any pending connection requests. Because the AcceptSocket and AcceptTcpClient methods block execution until the Start method has queued an incoming connection request, the method can be used to determine if connections are available before attempting to accept them.
The following code example checks the method. If a connection request is waiting to be accepted, then a call to the AcceptTcpClient method is made.
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())
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.