Tcl
Tcl
Move a Connection into Another Socket
See more Socket/SSL/TLS Examples
Demonstrates Socket.TakeConnection, which moves the active connection from one Socket into another. The receiving object first releases any connection it previously held.
Background. Unlike TakeSocket, TakeConnection does not add a member to a socket set. After success, the source socket holds no connection. This is useful for handing an accepted connection to a dedicated handler object.
Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
set listenSock [new_CkSocket]
set success [CkSocket_BindAndListen $listenSock 5000 25]
if {$success == 0} then {
puts [CkSocket_lastErrorText $listenSock]
delete_CkSocket $listenSock
exit
}
set connectedSock [new_CkSocket]
set success [CkSocket_AcceptNext $listenSock 20000 $connectedSock]
if {$success == 0} then {
puts [CkSocket_lastErrorText $listenSock]
delete_CkSocket $listenSock
delete_CkSocket $connectedSock
exit
}
# Move the active connection out of connectedSock and into another Socket object. Unlike
# TakeSocket, this does not add a member to a socket set. After success, connectedSock holds no
# connection.
set handlerSock [new_CkSocket]
set success [CkSocket_TakeConnection $handlerSock $connectedSock]
if {$success == 0} then {
puts [CkSocket_lastErrorText $handlerSock]
delete_CkSocket $listenSock
delete_CkSocket $connectedSock
delete_CkSocket $handlerSock
exit
}
puts "Connection moved to the handler socket."
delete_CkSocket $listenSock
delete_CkSocket $connectedSock
delete_CkSocket $handlerSock