SelectMode Wyliczenie

Definicja

Definiuje tryby sondowania dla Poll(Int32, SelectMode) metody .

public enum class SelectMode
public enum SelectMode
type SelectMode = 
Public Enum SelectMode
Dziedziczenie
SelectMode

Pola

SelectError 2

Tryb stanu błędu.

SelectRead 0

Tryb stanu odczytu.

SelectWrite 1

Tryb stanu zapisu.

Przykłady

Poniższy przykład sprawdza stan Socket przy użyciu wszystkich trzech SelectMode wartości wyliczenia. Wywołanie Socket.Poll metody przy użyciu wyliczonej wartości SelectWrite powinno zwrócić wartość 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

Uwagi

Wyliczenie SelectMode definiuje tryby sondowania, które można przekazać do Socket.Poll metody . Użyj wartości SelectRead, aby określić, czy nasłuchiwanie Socket ma przychodzące żądania połączenia. Użyj wartości SelectWrite, aby określić, czy element Socket jest zapisywalny. Użyj wartości SelectError, aby określić, czy w elemecie Socketwystępuje warunek błędu . Aby uzyskać wyjaśnienia dotyczące możliwości zapisu, czytelności i obecności warunków błędów, zobacz metodę Socket.Poll .

Dotyczy

Zobacz też