SelectMode SelectMode SelectMode SelectMode Enum

定义

Poll(Int32, SelectMode) 方法定义轮询模式。Defines the polling modes for the Poll(Int32, SelectMode) method.

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

字段

SelectError SelectError SelectError SelectError 2

错误状态模式。Error status mode.

SelectRead SelectRead SelectRead SelectRead 0

读状态模式。Read status mode.

SelectWrite SelectWrite SelectWrite SelectWrite 1

写状态模式。Write status mode.

示例

下面的示例使用所有三个Socket SelectMode枚举值检查的状态。The following example checks the status of a Socket using all three SelectMode enumeration values. Socket.Poll使用 SelectWrite 枚举值的调用应返回trueA call to Socket.Poll using the SelectWrite enumerated value should return 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 

注解

枚举定义可传递Socket.Poll给方法的轮询模式。 SelectModeThe SelectMode enumeration defines the polling modes that can be passed to the Socket.Poll method. 使用 SelectRead 值确定侦听Socket是否有传入的连接请求。Use the SelectRead value to determine if a listening Socket has incoming connection requests. 使用 SelectWrite 值确定Socket是否可写。Use the SelectWrite value to determine if a Socket is writeable. 使用 SelectError 值确定中是否存在错误情况SocketUse the SelectError value to determine if there is an error condition present on the Socket. 有关 writeability、可读性和错误情况的说明, 请参阅Socket.Poll方法。For explanations of writeability, readability, and the presence of error conditions, see the Socket.Poll method.

适用于

另请参阅