DataFlex
DataFlex
Receive an Exact Number of Bytes as Encoded Text
See more Socket/SSL/TLS Examples
Demonstrates Socket.ReceiveNBytesENC, which receives exactly the requested number of bytes and returns them encoded using a named encoding. It waits until the full count is received.
Background. Inactivity is controlled by
MaxReadIdleMs: the call fails if incoming bytes halt for longer than MaxReadIdleMs milliseconds before the full amount is received. The ENC methods move raw binary data to and from printable text using a named encoding such as base64 or hex.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoSocket
Boolean iBTls
Integer iMaxWaitMs
String sHex
String sTemp1
Boolean bTemp1
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
// MaxReadIdleMs controls the inactivity limit for receiving. The ReceiveNBytesENC call will fail if
// incoming bytes halt for longer than this many milliseconds before the full amount is received.
Set ComMaxReadIdleMs Of hoSocket To 15000
// Receive exactly the requested number of bytes and return them encoded using the named encoding.
// Unlike ReceiveBytesENC, this waits until the full count has been received.
Get ComReceiveNBytesENC Of hoSocket 16 "hex" To sHex
Get ComLastMethodSuccess Of hoSocket To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoSocket To sTemp1
Showln sTemp1
Procedure_Return
End
Showln sHex
End_Procedure