共用方式為


SelectMode 列舉

定義

定義輪詢模式,用於 Poll(Int32, SelectMode) 方法。

public enum class SelectMode
public enum SelectMode
type SelectMode = 
Public Enum SelectMode
繼承
SelectMode

欄位

SelectError 2

錯誤狀態模式。

SelectRead 0

讀取狀態模式。

SelectWrite 1

寫入狀態模式。

範例

下列範例會使用這三SelectModeSocket列舉值來檢查 的狀態。 使用 SelectWrite 列舉值的呼叫 Socket.Poll 應該會傳回 true

//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.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.
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 
End If

備註

列舉 SelectMode 定義可傳遞至 方法的 Socket.Poll 輪詢模式。 使用 SelectRead 值來判斷接 Socket 聽是否有連入連線要求。 使用 SelectWrite 值來判斷 是否 Socket 可寫入。 使用 SelectError 值來判斷 上 Socket是否有錯誤狀況。 如需可寫入性、可讀性和錯誤狀況存在的說明,請參閱 Socket.Poll 方法。

適用於

另請參閱