Pending Method
Determines if there are pending connection requests.
[C#] public bool Pending();
Return Value
true if connections are pending; otherwise, false.
Exceptions
Exception Type | Condition |
---|---|
InvalidOperationException | The listener has not been started with a call to Start. |
Remarks
This non-blocking method determines if there are any pending connection requests. Because the AcceptSocket and AcceptTcpClient methods block execution until Start has queued an incoming connection request, the Pending method can be used to determine if connections are available before attempting to accept them.
Example
[C#] The following example checks the Pending method. If a connection request is waiting to be accepted, then then a call to AcceptTcpClient is made.
[C#]
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());
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework