SelectMode Enumeración

Definición

Define los modos de sondeo del método Poll(Int32, SelectMode).

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

Campos

SelectError 2

Modo de estado de error.

SelectRead 0

Modo de estado de lectura.

SelectWrite 1

Modo de estado de escritura.

Ejemplos

En el ejemplo siguiente se comprueba el estado de un Socket objeto utilizando los tres SelectMode valores de enumeración. Una llamada a mediante Socket.Poll el valor enumerado SelectWrite debe devolver 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

Comentarios

La SelectMode enumeración define los modos de sondeo que se pueden pasar al Socket.Poll método . Use el valor SelectRead para determinar si una escucha tiene solicitudes de conexión entrantes Socket . Use el valor SelectWrite para determinar si se puede escribir.Socket Use el valor SelectError para determinar si hay una condición de error presente en .Socket Para obtener explicaciones sobre la capacidad de escritura, la legibilidad y la presencia de condiciones de error, consulte el Socket.Poll método .

Se aplica a

Consulte también