PowerBuilder
PowerBuilder
Wait for a Socket to Become Writable
See more Socket/SSL/TLS Examples
Demonstrates Socket.SelectForWriting, which waits for the socket, or sockets in a socket set, to become writable. It returns 1 if writable, 0 on timeout, or -1 on error.
Background. A timeoutMs of 0 performs a nonblocking poll. This is useful before attempting to send when the peer may be applying flow control.
Chilkat PowerBuilder Downloads
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 the socket (or sockets in a socket set) to become writable. Returns 1 if
// writable, 0 on timeout, or -1 on error.
li_Ready = loo_Socket.SelectForWriting(5000)
if li_Ready < 0 then
Write-Debug loo_Socket.LastErrorText
destroy loo_Socket
return
end if
if li_Ready <> 1 then
Write-Debug "The socket did not become writable before the timeout."
destroy loo_Socket
return
end if
Write-Debug "The socket is ready for writing."
destroy loo_Socket