Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

SelectMode Enumeration

Defines the polling modes for the Socket.Poll method.

Namespace: System.Net.Sockets
Assembly: System (in system.dll)

public enum SelectMode
public enum SelectMode
public enum SelectMode

 Member nameDescription
Supported by the .NET Compact FrameworkSelectErrorError status mode. 
Supported by the .NET Compact FrameworkSelectReadRead status mode. 
Supported by the .NET Compact FrameworkSelectWriteWrite status mode. 

The SelectMode enumeration defines the polling modes that can be passed to the Socket.Poll method. Use the SelectRead value to determine if a listening Socket has incoming connection requests. Use the SelectWrite value to determine if a Socket is writeable. Use the SelectError value to determine if there is an error condition present on the Socket. For explanations of writeability, readability, and the presence of error conditions, see the Socket.Poll method.

The following example checks the status of a Socket using all three SelectMode enumeration values. A call to Poll using the SelectWrite enumerated value should return true.

//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.
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, 
    ProtocolType.Tcp);
// Connects to host using IPEndPoint.
s.Connect(epHost);
if (!(s.get_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 should not print."
            + "Because this is not a listening Socket,"
            + " no incoming connecton requests are expected. ");
    }
    else {
        if (s.Poll(-1, SelectMode.SelectError)) {
            Console.WriteLine("This Socket has an error.");
        }
    }
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft