follow my heart...
分类:
2009-03-19 23:42:31
昨天还在说tcl语言非常不着调,今天却突然有种顿悟的感觉.稍后再写一下对TCL语言的其它想法,现在先写写基本的socket编程示例.
下面的例子是调试成功的,有兴趣的朋友直接可以照做即可:
server.tcl
set listenSocket [socket -server Accept 2540]
proc Accept {newSock addr port} {
puts "Accepted $newSock from $addr port $port"
} vwait forever
下面是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 “192.168.1.103” 8000 100