Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oSocket
LOCAL nBTls
LOCAL nMaxWaitMs
LOCAL oBd
nSuccess := 0
oSocket := CreateObject("Chilkat.Socket")
// Connect to the server using TLS.
nBTls := 1
nMaxWaitMs := 5000
nSuccess := oSocket:Connect("example.com", 5000, nBTls, nMaxWaitMs)
IF (nSuccess == 0)
? oSocket:LastErrorText
oSocket:destroy()
RETURN
ENDIF
// 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).
oBd := CreateObject("Chilkat.BinData")
nSuccess := oSocket:ReceiveUntilByteBd(10, oBd)
IF (nSuccess == 0)
? oSocket:LastErrorText
oSocket:destroy()
oBd:destroy()
RETURN
ENDIF
? "Received " + Str(oBd:NumBytes) + " bytes (including the delimiter)."
oSocket:destroy()
oBd:destroy()