Sample code for 30+ languages & platforms
VB.NET

Poll a Socket for Available Data

See more Socket/SSL/TLS Examples

Demonstrates Socket.PollDataAvailable, which performs a nonblocking check for readable activity and returns whether data or another read-ready condition is present.

Background. This lets an application check for incoming data without blocking, for example in an event loop that services multiple tasks.

Chilkat VB.NET Downloads

VB.NET
Dim success As Boolean = False

Dim socket As New Chilkat.Socket

'  Connect to the server using TLS.
Dim bTls As Boolean = True
Dim maxWaitMs As Integer = 5000
success = socket.Connect("example.com",5000,bTls,maxWaitMs)
If (success = False) Then
    Debug.WriteLine(socket.LastErrorText)
    Exit Sub
End If


'  Perform a nonblocking check for readable data.  Returns True when data or another read-ready
'  condition is present, and False when nothing is immediately available.
Dim bAvailable As Boolean = socket.PollDataAvailable()
If (bAvailable <> True) Then
    Debug.WriteLine("No data is immediately available.")
Else
    Debug.WriteLine("Data is available to read.")
End If