语言

SelectMode 枚举

定义

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

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

字段

名称 值 说明
SelectRead 0

读取状态模式。

SelectWrite 1

写入状态模式。

SelectError 2

错误状态模式。

示例

以下示例检查所有三Socket个SelectMode枚举值的状态。 使用 SelectWrite 枚举值的调用 Socket.Poll 应返回 true。

//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 。

适用于

另请参阅