下面是client.tcl
proc Socket_Client {host port timeout} {
global connected
after $timeout {set connected timeout}
set sock [socket -async $host $port]
fileevent $sock w {set connected ok}
vwait connected
fileevent $sock w {}
if {$connected == "timeout"} {
return -code error timeout
} else {
return $sock
}
}
Socket_Client "10.33.132.2" 2540 100