Tcl
Tcl
Duplicate a Socket Wrapper Sharing the Connection
See more Socket/SSL/TLS Examples
Demonstrates Socket.DupSocket, which populates a destination Socket with another wrapper that shares this object's underlying connection.
Background. The shared connection is reference-counted, and all wrappers operate on the same live connection. The destination first releases any connection it previously held.
Chilkat Tcl Downloads
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
}
# Create a second Socket wrapper that shares this object's underlying connection. Both wrappers
# operate on the same live connection; the shared connection is reference-counted.
set dupSock [new_CkSocket]
set success [CkSocket_DupSocket $socket $dupSock]
if {$success == 0} then {
puts [CkSocket_lastErrorText $socket]
delete_CkSocket $socket
delete_CkSocket $dupSock
exit
}
puts "Duplicate socket wrapper created."
delete_CkSocket $socket
delete_CkSocket $dupSock