SelectMode 列舉

定義

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

C#
public enum SelectMode
繼承
SelectMode

欄位

名稱 Description
SelectError 2

錯誤狀態模式。

SelectRead 0

讀取狀態模式。

SelectWrite 1

寫入狀態模式。

範例

下列範例會使用這三SelectModeSocket列舉值來檢查 的狀態。 使用 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

另請參閱