DataFlex
DataFlex
Check Whether a Socket Is Writable
See more Socket/SSL/TLS Examples
Demonstrates Socket.CheckWriteable, which waits for the connected socket to become writable. It returns 1 if writable, 0 if it did not become writable before the timeout, or -1 on error.
Background. A maxWaitMs of 0 performs a nonblocking poll. This is useful for flow control before attempting a large send.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoSocket
Boolean iBTls
Integer iMaxWaitMs
Integer iWritable
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 the socket to become writable. Returns 1 if writable, 0 if it did not
// become writable before the timeout, or -1 on error.
Get ComCheckWriteable Of hoSocket 5000 To iWritable
If (iWritable < 0) Begin
Get ComLastErrorText Of hoSocket To sTemp1
Showln sTemp1
Procedure_Return
End
If (iWritable <> 1) Begin
Showln "The socket did not become writable before the timeout."
Procedure_Return
End
Showln "The socket is writable."
End_Procedure