Bagikan melalui


SelectMode Enum

Definisi

Menentukan mode polling untuk metode .Poll(Int32, SelectMode)

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

Bidang

SelectError 2

Mode status kesalahan.

SelectRead 0

Mode status baca.

SelectWrite 1

Mode status tulis.

Contoh

Contoh berikut memeriksa status Socket menggunakan ketiga SelectMode nilai enumerasi. Panggilan ke Socket.Poll menggunakan nilai enumerasi SelectWrite harus mengembalikan 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

Keterangan

SelectMode Enumerasi mendefinisikan mode polling yang dapat diteruskan ke Socket.Poll metode . Gunakan nilai SelectRead untuk menentukan apakah mendengarkan Socket memiliki permintaan koneksi masuk. Gunakan nilai SelectWrite untuk menentukan apakah nilai Socket dapat ditulis. Gunakan nilai SelectError untuk menentukan apakah ada kondisi kesalahan pada Socket. Untuk penjelasan tentang penulisan, keterbacaan, dan adanya kondisi kesalahan, lihat Socket.Poll metode .

Berlaku untuk

Lihat juga