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

Dim instance As Socket Dim microSeconds As Integer Dim mode As SelectMode Dim returnValue As Boolean returnValue = instance.Poll(microSeconds, mode)
戻り値


Poll メソッドは Socket の状態を確認します。selectMode パラメータに SelectMode.SelectRead を指定して、Socket が読み取り可能かどうかを確認します。SelectMode.SelectWrite を指定して、Socket が書き込み可能かどうかを確認します。SelectMode.SelectError を使用してエラー条件を検出します。Poll は、指定した時間 (microseconds 単位) が経過するまで実行をブロックします。応答に対して無制限に待機する場合は、microSeconds パラメータを負の整数に設定します。複数ソケットの状態を確認する場合は、Select を使用するとよいでしょう。
![]() |
---|
SocketException が発生した場合は、SocketException.ErrorCode プロパティを使用して具体的なエラー コードを取得してください。このコードを取得したら、Windows Socket Version 2 API エラー コードのマニュアルからエラーの詳細情報を確認してください。これは MSDN ライブラリから入手できます。 |

ソケットを作成してサーバーに接続し、Poll を使用してソケットのステータスをチェックするコード例を次に示します。
'Creates the Socket for sending data over TCP. Dim s As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) ' Connects to host using IPEndPoint. s.Connect(EPhost) If Not s.Connected Then strRetPage = "Unable to connect to host" End If ' Use the SelectWrite enumeration to obtain Socket status. If s.Poll(- 1, SelectMode.SelectWrite) Then Console.WriteLine("This Socket is writable.") Else If s.Poll(- 1, SelectMode.SelectRead) Then Console.WriteLine(("This Socket is readable. ")) Else If s.Poll(- 1, SelectMode.SelectError) Then Console.WriteLine("This Socket has an error.") End If End If
//Creates the Socket for sending data over TCP. Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream , ProtocolType.Tcp ); // Connects to host using IPEndPoint. s.Connect(EPhost); if (!s.Connected) { strRetPage = "Unable to connect to host"; } // Use the SelectWrite enumeration to obtain Socket status. if(s.Poll(-1, SelectMode.SelectWrite)){ Console.WriteLine("This Socket is writable."); } else if (s.Poll(-1, SelectMode.SelectRead)){ Console.WriteLine("This Socket is readable." ); } else if (s.Poll(-1, SelectMode.SelectError)){ Console.WriteLine("This Socket has an error."); }
//Creates the Socket for sending data over TCP. Socket^ s = gcnew Socket( AddressFamily::InterNetwork, SocketType::Stream, ProtocolType::Tcp ); // Connects to host using IPEndPoint. s->Connect( EPhost ); if ( !s->Connected ) { strRetPage = "Unable to connect to host"; } // Use the SelectWrite enumeration to obtain Socket status. if ( s->Poll( -1, SelectMode::SelectWrite ) ) { Console::WriteLine( "This Socket is writable." ); } else if ( s->Poll( -1, SelectMode::SelectRead ) ) { Console::WriteLine( "This Socket is readable." ); } else if ( s->Poll( -1, SelectMode::SelectError ) ) { Console::WriteLine( "This Socket has an error." ); }
//Creates the Socket for sending data over TCP. Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream , ProtocolType.Tcp); // Connects to host using IPEndPoint. s.Connect(epHost); if (!(s.get_Connected())) { strRetPage = "Unable to connect to host"; } // Use the SelectWrite enumeration to obtain Socket status. if (s.Poll(-1, SelectMode.SelectWrite)) { Console.WriteLine("This Socket is writable."); } else { if (s.Poll(-1, SelectMode.SelectRead)) { Console.WriteLine("This should not print." + "Because this is not a listening Socket," + " no incoming connecton requests are expected. "); } else { if (s.Poll(-1, SelectMode.SelectError)) { Console.WriteLine("This Socket has an error."); } } }

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- Socket.Poll メソッドのページへのリンク