SelectMode 枚举

定义

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

C#
public enum SelectMode
继承
SelectMode

字段

名称 说明
SelectError 2

错误状态模式。

SelectRead 0

读状态模式。

SelectWrite 1

写状态模式。

示例

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

C#
//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.");
 }

注解

SelectMode枚举定义可传递给 方法的Socket.Poll轮询模式。 使用 SelectRead 值确定侦 Socket 听是否有传入的连接请求。 使用 SelectWrite 值确定 是否 Socket 可写。 使用 SelectError 值确定 上 Socket是否存在错误条件。 有关可写性、可读性和是否存在错误条件的说明,请参阅 Socket.Poll 方法。

适用于

产品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

另请参阅