Shaun Kulesa 在 2023年11月8日 星期三晚上7:32:31 [UTC+8] 的信中寫道:
I'm trying to run the tclhttpd web server example but every port I try on my university wifi or my remote linux virtual machine it will say the port is already in use.
couldn't open socket: address already in use
while executing
"socket -server [namespace code [list my connect]] -myaddr $ip $port"
(class "::httpd::server" method "start" line 20)
invoked from within
"HTTPD start"
I then try the python http server on the same port afterwards and it works.
package require httpd
httpd::server create HTTPD port 8039
HTTPD start
# Add in a dict based dispatcher
HTTPD plugin dispatch ::httpd::plugin.dict_dispatch
# Register the /hello uri to be answered by our new class
HTTPD uri add * /hello {mixin {content reply.hello}}
oo::class create ::reply.hello {
method content {} {
my puts "<HTML><HEAD><TITLE>My Example Server</TITLE></HEAD><BODY>"
my puts "<h1>Hello World!</h1>"
my puts "Nice to see you from [my request get REMOTE_HOST]"
my puts "The time is now [clock format [clock seconds]]"
my puts </BODY></HTML>
}
}
Hello,
I test in httpd 4.3.5.
I think you can try to remove "HTTPD start" this line, because it is not necessary.
And modify
HTTPD uri add * /hello {mixin {content reply.hello}}
To
HTTPD uri add * /hello [list mixin {content ::reply.hello}]
And if you are not in interactive mode, maybe you need to add "vwait forever" in last line.
So the script will be:
package require httpd
httpd::server create HTTPD port 8039
# Add in a dict based dispatcher
HTTPD plugin basic_url ::httpd::plugin.dict_dispatch
# Register the /hello uri to be answered by our new class
HTTPD uri add * /hello [list mixin {content reply.hello}]
clay::define ::reply.hello {
method content {} {
my puts "<HTML><HEAD><TITLE>My Example Server</TITLE></HEAD><BODY>"
my puts "<h1>Hello World!</h1>"
my puts "Nice to see you from [my request get REMOTE_HOST]"
my puts "The time is now [clock format [clock seconds]]"
my puts </BODY></HTML>
}
}
# If not in interactive mode
vwait forever
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)