DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoSocket
Boolean iBTls
Integer iMaxWaitMs
Integer iReady
String sTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatSocket)) To hoSocket
If (Not(IsComObjectCreated(hoSocket))) Begin
Send CreateComObject of hoSocket
End
// Connect to the server using TLS.
Move True To iBTls
Move 5000 To iMaxWaitMs
Get ComConnect Of hoSocket "example.com" 5000 iBTls iMaxWaitMs To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSocket To sTemp1
Showln sTemp1
Procedure_Return
End
// 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.
Get ComSelectForReading Of hoSocket 5000 To iReady
If (iReady < 0) Begin
Get ComLastErrorText Of hoSocket To sTemp1
Showln sTemp1
Procedure_Return
End
If (iReady <> 1) Begin
Showln "No data became available before the timeout."
Procedure_Return
End
Showln "The socket has data ready to read."
End_Procedure