DataFlex
DataFlex
Receive Bytes up to a Delimiter into a BinData
See more Socket/SSL/TLS Examples
Demonstrates Socket.ReceiveUntilByteBd, which reads bytes until a delimiter byte is encountered and appends all bytes up to and including the delimiter to a BinData.
Background. The delimiter is a raw byte value from 0 through 255. This is useful for framing schemes that terminate each message with a known delimiter byte.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoSocket
Boolean iBTls
Integer iMaxWaitMs
Variant vBd
Handle hoBd
String sTemp1
Integer iTemp1
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
// Read bytes until the delimiter byte is encountered, appending all bytes up to and including the
// delimiter to a BinData. The delimiter is a raw byte value from 0 through 255 (here the linefeed
// byte, decimal 10).
Get Create (RefClass(cComChilkatBinData)) To hoBd
If (Not(IsComObjectCreated(hoBd))) Begin
Send CreateComObject of hoBd
End
Get pvComObject of hoBd to vBd
Get ComReceiveUntilByteBd Of hoSocket 10 vBd To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSocket To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComNumBytes Of hoBd To iTemp1
Showln "Received " iTemp1 " bytes (including the delimiter)."
End_Procedure