• Tclhttpd not working on ports

    From Shaun Kulesa@21:1/5 to All on Wed Nov 8 03:32:28 2023
    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>
    }
    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter Dean@21:1/5 to Shaun Kulesa on Thu Nov 9 07:38:30 2023
    On 8/11/23 21:32, Shaun Kulesa wrote:
    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>
    }
    }
    what version of tclhttpd?
    Is it this?
    fossil clone https://core.tcl-lang.org/tclhttpd

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Shaun Kulesa@21:1/5 to All on Thu Nov 9 00:42:51 2023
    Hi,

    I am 99% sure my versions are from the tcllib, the version numbers are 4.3.4 and 4.3.5.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter Dean@21:1/5 to Peter Dean on Fri Nov 10 07:51:35 2023
    On 10/11/23 07:16, Peter Dean wrote:
    On 9/11/23 18:42, Shaun Kulesa wrote:
    Hi,

    I am 99% sure my versions are from the tcllib, the version numbers are
    4.3.4 and 4.3.5.


    hmm I don't see it in tcllib https://core.tcl-lang.org/tcllib/doc/trunk/embedded/md/toc.md

    nor do I see those in tclhttpd branch list https://core.tcl-lang.org/tclhttpd/brlist

    neither is the wiki page any help
    https://wiki.tcl-lang.org/page/TclHttpd

    what am I missing?
    oops the penny finally dropped. We're not talking about tclhttpd at all
    but httpd. I'll get me coat.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter Dean@21:1/5 to Shaun Kulesa on Fri Nov 10 07:16:21 2023
    On 9/11/23 18:42, Shaun Kulesa wrote:
    Hi,

    I am 99% sure my versions are from the tcllib, the version numbers are 4.3.4 and 4.3.5.


    hmm I don't see it in tcllib https://core.tcl-lang.org/tcllib/doc/trunk/embedded/md/toc.md

    nor do I see those in tclhttpd branch list https://core.tcl-lang.org/tclhttpd/brlist

    neither is the wiki page any help
    https://wiki.tcl-lang.org/page/TclHttpd

    what am I missing?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Shaun Kulesa on Fri Nov 10 02:43:00 2023
    Shaun Kulesa <[email protected]> wrote:
    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

    It appears that for httpd 4.3.5 that simply creating the server object
    creates the server socket.

    This below is from linux. If I do this:

    $ netstat -l -v -n -p 2> /dev/null | grep 8039

    I have nothing listening on port 8039.

    Now if I do:

    $ rlwrap tclsh
    % package require httpd
    4.3.5
    %httpd::server create HTTPD port 8039
    ::HTTPD

    And nothing more, and check netstat, I have tclsh listening on 8039:

    $ netstat -l -v -n -p 2> /dev/null | grep 8039
    tcp 0 0 127.0.0.1:8039 0.0.0.0:* LISTEN 29158/tclsh

    Then, attempting to do HTTPD start results in the same 'address in use'
    error you are seeing:

    % HTTPD start
    couldn't open socket: address already in use

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Shaun Kulesa@21:1/5 to All on Fri Nov 10 03:49:13 2023
    The examples I have found either don't keep the code running or have errors (including the man page).

    Is there a good alternative to httpd?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Danilo Chang@21:1/5 to All on Fri Nov 10 06:04:30 2023
    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)