Socket.Select Method (IList, IList, IList, Int32)
Determines the status of one or more sockets.
Assembly: System (in System.dll)
Public Shared Sub Select ( checkRead As IList, checkWrite As IList, checkError As IList, microSeconds As Integer )
The time-out value, in microseconds. A -1 value indicates an infinite time-out.
Socket instances. You must place one or more sockets into an IList before you can use the method. Check for readability by calling with the IList as the checkRead parameter. To check your sockets for writability, use the checkWrite parameter. For detecting error conditions, use checkError. After calling , the IList will be filled with only those sockets that satisfy the conditions.is a static method that determines the status of one or more
If you are in a listening state, readability means that a call to Accept will succeed without blocking. If you have already accepted the connection, readability means that data is available for reading. In these cases, all receive operations will succeed without blocking. Readability can also indicate whether the remote Socket has shut down the connection; in that case a call to Receive will return immediately, with zero bytes returned.
returns when at least one of the sockets of interest (the sockets in the checkRead, checkWrite, and checkError lists) meets its specified criteria, or the microSeconds parameter is exceeded, whichever comes first. Setting microSeconds to -1 specifies an infinite time-out.
If you make a nonblocking call to Connect, writability means that you have connected successfully. If you already have a connection established, writability means that all send operations will succeed without blocking.
If you have made a non-blocking call to Connect, the checkerror parameter identifies sockets that have not connected successfully.
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.
The following code example usesto determine which listening sockets have a connection request.
Dim ipHostEntry As IPHostEntry = Dns.Resolve(Dns.GetHostName()) Dim ipAddress As IPAddress = ipHostEntry.AddressList(0) Dim socket0 As Socket = Nothing Dim socket1 As Socket = Nothing Dim socket2 As Socket = Nothing Dim socket3 As Socket = Nothing Dim socket4 As Socket = Nothing Dim socket5 As Socket = Nothing Dim listenList As New ArrayList() listenList.Add(socket0) listenList.Add(socket1) listenList.Add(socket2) Dim acceptList As New ArrayList() acceptList.Add(socket3) acceptList.Add(socket4) acceptList.Add(socket5) Dim i As Integer For i = 0 To 2 listenList(i) = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) CType(listenList(i), Socket).Bind(New IPEndPoint(ipAddress, 11000 + i)) CType(listenList(i), Socket).Listen(10) Next i 'Only the sockets that contain a connection request 'will remain in listenList after Select returns. Socket.Select(listenList, Nothing, Nothing, 1000) For i = 0 To listenList.Count - 1 acceptList(i) = CType(listenList(i), Socket).Accept() Next i
Available since 1.1