Sample code for 30+ languages & platforms
PowerBuilder

Wait for a Socket to Become Readable

See more Socket/SSL/TLS Examples

Demonstrates Socket.SelectForReading, which waits for read-ready activity on the socket, or on any contained socket when the object is a socket set. It returns 1 if ready, 0 on timeout, or -1 on error.

Background. A timeoutMs of 0 performs a nonblocking poll. With a socket set, this monitors many connections at once for readability.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Socket
integer li_BTls
integer li_MaxWaitMs
integer li_Ready

li_Success = 0

loo_Socket = create oleobject
li_rc = loo_Socket.ConnectToNewObject("Chilkat.Socket")
if li_rc < 0 then
    destroy loo_Socket
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  Connect to the server using TLS.
li_BTls = 1
li_MaxWaitMs = 5000
li_Success = loo_Socket.Connect("example.com",5000,li_BTls,li_MaxWaitMs)
if li_Success = 0 then
    Write-Debug loo_Socket.LastErrorText
    destroy loo_Socket
    return
end if

//  Wait up to 5 seconds for read-ready activity on the socket (or, for a socket set, on any contained
//  socket).  Returns 1 if ready, 0 on timeout, or -1 on error.
li_Ready = loo_Socket.SelectForReading(5000)
if li_Ready < 0 then
    Write-Debug loo_Socket.LastErrorText
    destroy loo_Socket
    return
end if

if li_Ready <> 1 then
    Write-Debug "No data became available before the timeout."
    destroy loo_Socket
    return
end if

Write-Debug "The socket has data ready to read."


destroy loo_Socket