| Dave (from the UK) 2007-02-21, 7:15 pm |
| I'm using the 'tcltelnet' telnet client:
http://tmartin.org/tcltelnet/
to connect to a chess server, which uses the telnet protocol.
The connection is working OK, but I am trying to handle errors gracefully.
The following code:
if {[catch {set ::pt [telnet::open $server $port]} errmsg]} {
tk_messageBox -type ok -icon error -message "error"
return
} {
after 200 [telnet::write $::pt "$user\n"]
after 1000 [telnet::write $::pt "pass\n"]
}
works fine if
1) The connection to the server is made properly.
2) The connection can not be made (for example, the server is not a
valid server)
However, a problem occurs if the server accepts the telnet connection,
but can't do anything very sensible with it but just hangs, as will
happen if you telnet to an ftp or HTTP sever for example.
teal /export/home/drkirkby % telnet www.google.com 80
Trying 209.85.129.104...
Connected to www.l.google.com.
Escape character is '^]'.
That would stay there for a long time, which hangs the Tcl application.
Is there a way of getting the connection to break if it has not returned
for some set period?
The manual page for teltelnet
http://tmartin.org/tcltelnet/telnet.html#1
says the channel can be configured with fconfigure. But looking at the
docs on that
http://www.tcl.tk/man/tcl8.0/TclCmd/fconfigure.htm
I can't see how to add a timeout.
--
Dave (from the UK)
Please note my email address changes periodically to avoid spam.
It is always of the form: month-year@althorne.org
Hitting reply will work for a few months only - later set it manually.
http://chessdb.sourceforge.net/ - a Free open-source Chess Database
|