Tcl Library Source Code

View Ticket
Login
Ticket UUID: 79c916b904bb11c028feefd9251f2fa18b637b08
Title: couldn't open socket: address already in use
Type: Bug Version: 8.6 / 8.7
Submitter: anonymous Created on: 2020-06-04 17:35:15
Subsystem: httpd Assigned To: hypnotoad
Priority: 7 High Severity: Severe
Status: Open Last Modified: 2023-05-12 11:39:08
Resolution: None Closed By: nobody
    Closed on:
Description:
Using the following snippet from the TCLers wiki:
https://wiki.tcl-lang.org/page/httpd+%28Tcllib%29

The following error occurs: 
couldn't open socket: address already in use. 
Doesn't matter what port number is used and if ran in root or normal user.

===
mookie@fantasy:~ % tclsh8.7
% package require httpd 4.0
4.1.1
% httpd::server create HTTPD port 8015
::HTTPD
%  HTTPD start
couldn't open socket: address already in use

==
Debian Host
Setting up tcllib (1.18-dfsg-3) ...
mookie@voice:~# tclsh
% package require httpd 4.0
4.0
% httpd::server create HTTPD port 8015
::HTTPD
% HTTPD start
couldn't open socket: address already in use

FreeBSD Hosts: All compile from source
Versions: 10.3, 11.0 and 12.0

Debian Host: installed via apt-get
Versions: 9.0
User Comments: nat-418 added on 2023-05-12 11:39:08:
Following the above instructions, I have the same issue. I am on an X86_64 Linux 6.2.11 machine running Tcl version 8.6.

mookie added on 2020-06-04 18:35:39:
Tcllib came from tcl8.7a1-src.tar.gz which is: tcllib-1.19
However as strange, running the example httpd within tcllib it runs just fine.

Running your syntax above:

clay is not found:
% clay::define ::httpd::server {
   method debug args {
      puts $args
   }
}
invalid command name "clay::define"

however if I use debug with auto, I get the follow result

% package require httpd 4.0
4.1.1
% httpd::server create HTTPD port auto debug 1
::HTTPD
% HTTPD start
after#2
%

If I don't use auto, I get the same error as before.

hypnotoad added on 2020-06-04 18:17:27:
Ah.. and you'll have to also add the following snippet:

# Load the package
package require httpd 4.0

# Add a non-empty debug method
clay::define ::httpd::server {
   method debug args { 
      puts $args
   }
}
 httpd::server create HTTPD port 8015 debug 1

(And if that still fails)

 httpd::server create HTTPD port auto debug 1

hypnotoad added on 2020-06-04 18:13:29:
The error is coming from the Tcl socket command. In some applications I have run into issues with the way the nettool module (also one of my creations) doles out ports on certain platforms.

Which version of Tcllib are you using? Is it a fossil checkout or a release snapshot? That will help me try to recreate the issue on my end.

In the mean time, try the following so we can see what port it’s actually attempting to open:

httpd::server create HTTPD port 8015 debug 1