Sample code for 30+ languages & platforms
Tcl

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

Tcl

load ./chilkat.dll

set success 0

set socket [new_CkSocket]

#  Connect to the server using TLS.
set bTls 1
set maxWaitMs 5000
set success [CkSocket_Connect $socket "example.com" 5000 $bTls $maxWaitMs]
if {$success == 0} then {
    puts [CkSocket_lastErrorText $socket]
    delete_CkSocket $socket
    exit
}

#  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).
set bd [new_CkBinData]

set success [CkSocket_ReceiveUntilByteBd $socket 10 $bd]
if {$success == 0} then {
    puts [CkSocket_lastErrorText $socket]
    delete_CkSocket $socket
    delete_CkBinData $bd
    exit
}

puts "Received [CkBinData_get_NumBytes $bd] bytes (including the delimiter)."

delete_CkSocket $socket
delete_CkBinData $bd