(Tcl) Send Bytes on a Socket Connection
Demonstrates how to send a mixture of binary (non-text) and text bytes on a socket connection.
load ./chilkat.dll
# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set socket [new_CkSocket]
# Connect to some host:port
set ssl 0
set maxWaitMillisec 20000
set port 5555
set success [CkSocket_Connect $socket "test.com" $port $ssl $maxWaitMillisec]
if {$success != 1} then {
puts [CkSocket_lastErrorText $socket]
delete_CkSocket $socket
exit
}
# We wish to send a 0x00 byte followed by the us-ascii string "10800"
set bd [new_CkBinData]
CkBinData_AppendByte $bd 0
CkBinData_AppendString $bd "10800" "utf-8"
# Send the entire contents of bd.
set success [CkSocket_SendBd $socket $bd 0 0]
if {$success != 1} then {
puts [CkSocket_lastErrorText $socket]
delete_CkSocket $socket
delete_CkBinData $bd
exit
}
delete_CkSocket $socket
delete_CkBinData $bd
|