Sample code for 30+ languages & platforms
Lianja

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 Lianja Downloads

Lianja
llSuccess = .F.

loSocket = createobject("CkSocket")

//  Connect to the server using TLS.
llBTls = .T.
lnMaxWaitMs = 5000
llSuccess = loSocket.Connect("example.com",5000,llBTls,lnMaxWaitMs)
if (llSuccess = .F.) then
    ? loSocket.LastErrorText
    release loSocket
    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).
loBd = createobject("CkBinData")
llSuccess = loSocket.ReceiveUntilByteBd(10,loBd)
if (llSuccess = .F.) then
    ? loSocket.LastErrorText
    release loSocket
    release loBd
    return
endif

? "Received " + str(loBd.NumBytes) + " bytes (including the delimiter)."


release loSocket
release loBd