Socket.Poll Method (Int32, SelectMode)


Determines the status of the Socket.

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

Public Function Poll (
	microSeconds As Integer,
	mode As SelectMode
) As Boolean


Type: System.Int32

The time to wait for a response, in microseconds.

Type: System.Net.Sockets.SelectMode

One of the SelectMode values.

Return Value

Type: System.Boolean

The status of the Socket based on the polling mode value passed in the mode parameter.


Return Value


true if Listen has been called and a connection is pending;


true if data is available for reading;


true if the connection has been closed, reset, or terminated;

otherwise, returns false.


true, if processing a Connect, and the connection has succeeded;


true if data can be sent;

otherwise, returns false.


true if processing a Connect that does not block, and the connection has failed;


true if OutOfBandInline is not set and out-of-band data is available;

otherwise, returns false.

Exception Condition

The mode parameter is not one of the SelectMode values.


An error occurred when attempting to access the socket. See remarks below.


The Socket has been closed.

The Poll method will check the state of the Socket. Specify SelectMode.SelectRead for the selectMode parameter to determine if the Socket is readable. Specify SelectMode.SelectWrite to determine if the Socket is writable. Use SelectMode.SelectError to detect an error condition. Poll will block execution until the specified time period, measured in microseconds, elapses. Set the microSeconds parameter to a negative integer if you would like to wait indefinitely for a response. If you want to check the status of multiple sockets, you might prefer to use the Select method.


If you receive a SocketException, use the SocketException.ErrorCode property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.


This method cannot detect certain kinds of connection problems, such as a broken network cable, or that the remote host was shut down ungracefully. You must attempt to send or receive data to detect these kinds of errors.


This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in the .NET Framework.

The following code example creates a socket, connects to a server, and uses Poll to check the status of the socket.

'Creates the Socket for sending data over TCP.
Dim s As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

' Connects to host using IPEndPoint.
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.")
   If s.Poll(- 1, SelectMode.SelectRead) Then
      Console.WriteLine(("This Socket is readable. "))
      If s.Poll(- 1, SelectMode.SelectError) Then
         Console.WriteLine("This Socket has an error.")
      End If
   End If 
End If 

.NET Framework
Available since 1.1
Return to top