If I send the server an empty line it will close the socket without notice, so if the server does not close the socket, the process controlling the port is stalled. Can this somehow be indicated? I don't know a "stalled" server to check, so I dont know if my current code would already check it.
in my current version I believe EOF would be always true, because the server sends nothing and gets returns always -1 (meaning there is nothing to get).
Would it be wise to make a -async connection and a fileevent? but would fileevent trigger if there is only an EOF to read?
another thing, can I phrase the catch variable output if the connection failed due timeout or due closed port?
Code: Select all
proc getzwstatus {} {
global zwstat zwping zwip
set zwstart [clock clicks -milliseconds]
if { [catch {set sock [socket $zwip 2593]}] } {
set zwstat 0
} else {
puts $sock ""
flush $sock
gets $sock trash
if { [eof $sock] } {
set zwstat 1
} else {
set zwstat 2
}
close $sock
}
set zwping [expr {[clock clicks -milliseconds] - $zwstart}]
return 0
}
PS:
Code: Select all
proc getzwstatus {} {
global zwstat zwstart zwip
set zwstart [clock clicks -milliseconds]
set sock [socket -async $zwip 2593]
puts $sock ""
flush $sock
fileevent $sock readable [list getzwstatus:cb $sock]
return 0
}
proc getzwstatus:cb {sock} {
global zwstat zwstart zwping
gets $sock trash
set trash2 [fconfigure $sock -error]
set zwstat 1
close $sock
set zwping [expr {[clock clicks -milliseconds] - $zwstart}]
putidx 10 "'$trash' '$trash2'"
return 0
}
yeah, but how do I get these errors? how can I check if the function is called, because of an error or because there is data to read? @_o. [fconfigure $sock -error] dosent return errors, if the socket has been closed remotely at least, havent tried yet, what it returns, if the socket connect has been refused.A channel is also considered to be readable if an end of file or error condition is present on the underlying file or device. It is important for script to check for these conditions and handle them appropriately; for example, if there is no special check for end of file, an infinite loop may occur where script reads no data, returns, and is immediately invoked again.