SelectMode 枚举

定义

Poll(Int32, SelectMode) 方法定义轮询模式。

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

字段

SelectError 2

错误状态模式。

SelectRead 0

读状态模式。

SelectWrite 1

写状态模式。

示例

以下示例使用所有三SelectMode个枚举值检查 的状态Socket。 使用 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 方法。

适用于

另请参阅