To illustrate the problem a code snippet is provided at the bottom.
What it does is:
- setup a listen port
- when a telnet client connects it will send out a request to a webserver and the idx of the client is stored in a variable
- the webserver will provide data which is forwarded to the client
- when the webserver terminates the connection, the connection with the client should be terminated through a killdcc
It is this last step that fails with an "Tcl error [forward:server:status]: invalid idx"
For some reason the idx is not recognised as a valid idx, eventhough a connection with the client exists under that idx.
Performing a manual ".tcl killdcc clientidx" on the partyline terminates the client connection, however.
Anyone any idea?
Code: Select all
#---------------------------------------------------------------------
# set up listen port
#---------------------------------------------------------------------
listen 35000 script forward:onconnect
#---------------------------------------------------------------------
# When a client connects, make an outgoing connection to the server.
#---------------------------------------------------------------------
proc forward:onconnect { clientidx } {
global forwardidx
putlog "Client connection on IDX: $clientidx"
set forwardidx $clientidx
control $clientidx forward:client:ignore
# connect to website and submit request
set hostname "www.egghelp.org"
set servidx [connect $hostname 80]
control $servidx forward:server:status
putdcc $servidx "GET / HTTP/0.9"
putdcc $servidx ""
putlog "Client ($clientidx) connected to server ($servidx)"
return 0
}
#---------------------------------------------------------------------
# ignore client text
#---------------------------------------------------------------------
proc forward:client:ignore { clientidx text } {
putlog "CLIENT ($clientidx): $text"
if { $text == "" } { return 1 }
return 0
}
#---------------------------------------------------------------------
# forward all data from server to client
# If the server closed the connection, close connection with client.
#---------------------------------------------------------------------
proc forward:server:status { servidx text } {
global forwardidx
set clientidx $forwardidx
# Server closed connection?
if { $text == "" } {
putlog "Server ($servidx) closed connection."
# The server closed the connection and now we want to close
# the connection with the client.
putlog "Killing Client ($clientidx)"
# Here it fails! :(
# Would assme that killdcc takes one argument (i.e. the idx)
# and simply kills the connection.
# But instead we get:
# Tcl error [forward:server:status]: invalid idx
killdcc $clientidx
return 1
}
putdcc $clientidx "$text\r"
return 0
}