Tcl
Tcl
Move a Connection into a Socket Set
See more Socket/SSL/TLS Examples
Demonstrates Socket.TakeSocket, which moves a connection into a newly created member of this object's socket set. After one or more calls, the object acts as a set of sockets.
Background. A socket set groups multiple connections so they can be monitored together with the SelectForReading and SelectForWriting methods. After success, the source socket holds no connection.
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 connection out of connectedSock and into a newly created member of this object's socket
# set. After one or more such calls, socketSet acts as a set of connected sockets (useful with the
# SelectForReading / SelectForWriting methods). After success, connectedSock holds no connection.
set socketSet [new_CkSocket]
set success [CkSocket_TakeSocket $socketSet $connectedSock]
if {$success == 0} then {
puts [CkSocket_lastErrorText $socketSet]
delete_CkSocket $listenSock
delete_CkSocket $connectedSock
delete_CkSocket $socketSet
exit
}
puts "Connection added to the socket set."
delete_CkSocket $listenSock
delete_CkSocket $connectedSock
delete_CkSocket $socketSet