Tk Library Source Code

View Ticket
Login
Ticket UUID: 2943788
Title: couldn't open socket: connection refused
Type: Bug Version: None
Submitter: hm2k Created on: 2010-02-01 13:00:26
Subsystem: ntp Assigned To: patthoyts
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2010-02-01 20:20:53
Resolution: None Closed By: patthoyts
    Closed on: 2010-02-01 13:20:53
Description:
proc tz:gettime { server } {
  package require time;
  set time "";
  while {$time == ""} {
    set tok [::time::gettime $server];
    set time [::time::unixtime $tok];
  }
  return $time;
}

puts [tz:gettime "pool.ntp.org"];

Tcl error [tz:gettime]: couldn't open socket: connection refused

How to I get around this error so it tries another server...
User Comments: patthoyts added on 2010-02-01 20:20:53:

allow_comments - 1

Just do it again if you get an error. However, you are using this wrong and will leak arrays if you run this alot. Re-read the manual page and pay attention to 
"Once you have finished, you should use [cmd cleanup] to release all resources. The default port is [const 37]."

See the example too. You get a token and you should use that to check for errors before trying to use the time value.
if {[time::status $tok] ne "ok"} {
  puts "something bad: [time::error $tok]"
  ...retry with next server...
}