当尝试通过TCL服务器返回多行输出时,即使客户端能够接收所有数据,服务器也会报告管道中断。
服务器:
proc Echo_Server {port} {
set s [socket -server EchoAccept $port]
vwait forever
}
proc EchoAccept {sock addr port} {
puts "Accept $sock from $addr port $port"
fconfigure $sock -buffering line
fileevent $sock readable [list Echo $sock]
}
proc Echo {sock} {
if { [eof $sock] || [catch {gets $sock line}] } {
puts "Close $sock"
close $sock
} else {
set returnData "
Hi
How are you?
This is test data
Close
"
puts $sock $returnData
puts $sock "EOF"
flush $sock
}
}
Echo_Server 2500
vwait forever
用于发送/接收数据的客户端代码:
proc Echo_Client {host port} {
set s [socket $host $port]
fconfigure $s -buffering full -buffersize 1000000
#fconfigure $s -buffering line -blocking 0
return $s
}
set s [Echo_Client localhost 2500] ; puts $s "dummy command" ; flush $s
set pp 1 ; while { $pp == 1 } { set line [gets $s] ; puts $line ; if { [regexp "EOF" $line] } { set pp 0 } } ; flush $s ; close $s
客户端收到从服务器发送的数据,但服务器报告以下内容:
% source /edascratch/nobackup/sanjaynn/scripts/simple_server.tcl
Accept sock6 from 127.0.0.1 port 59814
error writing "sock6": broken pipe
while executing
"puts $sock $returnData"
(procedure "Echo" line 15)
invoked from within
"Echo sock6"
我明显缺少什么吗?