TcpListener.Pending メソッド
アセンブリ: System (system.dll 内)

Dim instance As TcpListener Dim returnValue As Boolean returnValue = instance.Pending
接続が保留中の場合は true。それ以外の場合は false。


この非ブロッキング メソッドは、保留になっている接続要求がないかどうかを確認します。AcceptSocket メソッドおよび AcceptTcpClient メソッドは、Start メソッドが受信接続要求をキューに置くまで実行をブロックするため、Pending メソッドは、接続要求を受け取る前に接続が使用可能かどうかを確認するときにも使用できます。

Pending メソッドをチェックするコード例を次に示します。受け入れを待機している接続要求があると、AcceptTcpClient メソッドが呼び出されます。
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())
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 { // 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").get_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.get_LocalEndpoint())).get_Address().ToString()) + "on port number " + ((Int32)((IPEndPoint) (tcpListener.get_LocalEndpoint())).get_Port()).ToString());

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からTcpListener.Pending メソッドを検索する場合は、下記のリンクをクリックしてください。

- TcpListener.Pending メソッドのページへのリンク