Forum OpenACS Q&A: Response to tcllib nntp

Collapse
3: Response to tcllib nntp (response to 1)
Posted by James Thornton on
Thanks Dan. I have learned that if you don't specify a name for the connection, it will create a new 'unique' name in the form of nntp0, nntp1, nntp3, etc. This allows for reloading & serving up of multiple pages because if nntp0 is taken, it will create nntp1. There is also a "quit" command that "quits the nntp session, closes the socket, and deletes the command that was created for the connection."

Placing this code in a standard Tcl page works reasonably well:

# open a socket connection to th NNTP server and 
# create a new nntp object with an associated global Tcl command 
set NH [::nntp::nntp]

# send authentication information to the server 
$NH authinfo "username" "password"

# query the server for the server's current date
set value [$NH date] 

# gracefully close the connection 
# after sending a NNTP QUIT command down the socket
$NH quit
However, it's not perfect -- it you keep hitting reload fast enough, something happens to cause the next connection attempts to timeout (if you wait a while, it will start working again):
Error: couldn't open socket: connection timed out
couldn't open socket: connection timed out
    while executing
"socket $data(host) $data(port)"
    (procedure "::nntp::nntp" line 62)
    invoked from within
"::nntp::nntp $news"
    invoked from within
"set NH [::nntp::nntp $news]"
    (file "/web/james/www/try/nntp.tcl" line 13)
    invoked from within
"source $ad_conn(file)"
    (procedure "ad_handle_abstract_url" line 67)
    invoked from within
"ad_handle_abstract_url cns206 {}"