SelectMode Enumeração

Definição

Define os modos de sondagem para o método Poll(Int32, SelectMode).

public enum class SelectMode
public enum SelectMode
type SelectMode = 
Public Enum SelectMode
Herança
SelectMode

Campos

SelectError 2

Modo de status de erro.

SelectRead 0

Modo de status de leitura.

SelectWrite 1

Modo de status de gravação.

Exemplos

O exemplo a seguir verifica o status de um Socket usando os três SelectMode valores de enumeração. Uma chamada para Socket.Poll usar o valor enumerado SelectWrite deve retornar 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

Comentários

A SelectMode enumeração define os modos de sondagem que podem ser passados para o Socket.Poll método. Use o valor SelectRead para determinar se uma escuta Socket tem solicitações de conexão de entrada. Use o valor SelectWrite para determinar se um Socket é gravável. Use o valor SelectError para determinar se há uma condição de erro presente no Socket. Para obter explicações sobre gravabilidade, legibilidade e presença de condições de erro, consulte o Socket.Poll método.

Aplica-se a

Confira também