Socket.Poll メソッドとは? わかりやすく解説

Socket.Poll メソッド

Socketステータス確認します

名前空間: System.Net.Sockets
アセンブリ: System (system.dll 内)
構文構文

Public Function Poll ( _
    microSeconds As Integer, _
    mode As SelectMode _
) As Boolean
Dim instance As Socket
Dim microSeconds As Integer
Dim mode As SelectMode
Dim returnValue As Boolean

returnValue = instance.Poll(microSeconds, mode)
public bool Poll (
    int microSeconds,
    SelectMode mode
)
public:
bool Poll (
    int microSeconds, 
    SelectMode mode
)
public boolean Poll (
    int microSeconds, 
    SelectMode mode
)
public function Poll (
    microSeconds : int, 
    mode : SelectMode
) : boolean

パラメータ

microSeconds

マイクロ秒単位待機時間

mode

SelectMode 値の 1 つ

戻り値

モード

戻り値

SelectRead

Listen呼び出されており、接続保留中の場合true

または

データ読み取ることができる場合true

または

接続閉じているリセットされている、または終了している場合true

それ以外場合は、false返します

SelectWrite

Connect処理し接続成功した場合true

または

データ送信できる場合true

それ以外場合は、false返します

SelectError

ブロックしない Connect処理し接続失敗した場合true

または

OutOfBandInline が設定されておらず、帯域外データ使用できる場合true

それ以外場合は、false返します

例外例外
例外種類条件

NotSupportedException

mode パラメータが、SelectMode 値の 1 つではありません。

SocketException

ソケットへのアクセス試みているときにエラー発生しました。以下の解説参照してください

ObjectDisposedException

Socket閉じられています。

解説解説

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.");
        }
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からSocket.Poll メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からSocket.Poll メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からSocket.Poll メソッドを検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Socket.Poll メソッド」の関連用語

Socket.Poll メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Socket.Poll メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS