我正在编写一个套接字实用程序来将客户端传送到服务器。当从客户端输入到套接字时,服务器正在接收它。但是,当从服务器输入套接字时,客户端无法读取。检查fblocked $频道时。它是1.我已经尝试了一切,包括添加新行,...请帮忙。
以下是我的代码
proc read_command { sock } {
variable self
global connected
set len [gets $sock line]
set bl [fblocked $sock]
puts "Characters Read: $len Fblocked: $bl"
if {$len < 0} {
if {$bl} {
puts "Input is blocked"
} else {
set connected 1
puts "The socket was closed - closing my end"
close $sock
}
} else {
if {!$bl} {
puts "Read $len characters: $line"
catch {uplevel #0 $line} output
puts "1==>$output<=="
puts $sock "$output"
puts $sock "\n"
flush $sock
}
}
}
proc client { host port } {
variable self
set s [socket $host $port]
set self(csock) $s
set self($s,addr) $host
set self($s,port) $port
fconfigure $s -buffering line -blocking 0
return $s
}
proc prun { sock args} {
variable self
set result [list]
set cmd $args
set cmd [regsub -all {(^\s*\{)||(\}\s*$)} $cmd ""]
set cmd [string trimleft $cmd]
set o1 [eval $cmd]
#catch {uplevel #0 $cmd} o1
puts "1_$sock ==> $o1"
lappend result $o1
#--------------
puts $sock $cmd
flush $sock
set bl [fblocked $sock]
set file [read $sock]
set bl [fblocked $sock]
puts "Fblocked: $bl"
puts "Output: $file"
puts "2_$Comm::self(csock) ==> $file ==> $bl"
lappend result $file
return $result
}
这是我如何运行它。
下面是代码:1。在服务器shell上
$ server
2.在客户端shell上
$ set s [client $addr $port]
3.调用proc从客户端shell获取值,然后将命令发送到服务器以从服务器shell获取值,并将该值返回给客户端。
$ set res [prun $s {set val [get_attribute [get_nets mynet] pin_capacitance_max]}]
你写了:
puts "2_$Comm::self(csock) ==> $file ==> $bl"
并用变量定义了self。你在用包吗?可能是你忘了与之相关的东西。
对于测试,您可以使用全局但使用数组会稍微复杂一些。