SelectMode Enumerazione

Definizione

Definisce le modalità di polling per il metodo Poll(Int32, SelectMode).

public enum class SelectMode
public enum SelectMode
type SelectMode = 
Public Enum SelectMode
Ereditarietà
SelectMode

Campi

SelectError 2

Modalità stato di errore.

SelectRead 0

Modalità stato di lettura.

SelectWrite 1

Modalità stato di scrittura.

Esempio

Nell'esempio seguente viene controllato lo stato di un Socket oggetto usando tutti e tre SelectMode i valori di enumerazione. Una chiamata all'uso Socket.Poll del valore enumerato SelectWrite deve restituire 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

Commenti

L'enumerazione SelectMode definisce le modalità di polling che possono essere passate al Socket.Poll metodo. Usare il valore SelectRead per determinare se un ascolto Socket ha richieste di connessione in ingresso. Utilizzare il valore SelectWrite per determinare se un Socket oggetto è scrivibile. Usare il valore SelectError per determinare se è presente una condizione di errore nell'oggetto Socket. Per spiegazioni della scrittura, della leggibilità e della presenza di condizioni di errore, vedere il Socket.Poll metodo .

Si applica a

Vedi anche