Version 26 of Tclhttpd - Getting Started

Updated 2005-11-30 03:03:14

Getting Tclhttpd

You have several choices, mentioned on the Tclhttpd page:

  1. Starkit Distribution - batteries included
  2. Sourceforge Distribution - batteries included
  3. Snapshots - daily (roughly)
  4. CVS - instantaneous (subject to SF outage)

Choose one. CVS is likely to be the most up-to-date, snapshots next most up-to-date. Distributions most convenient, but currently have old bugs.

Grab your source, read the README.

There are pretty extensive online manuals, documentation and even a chapter from a book ... but of course you need to get tclhttpd up and running before you can read them.

There are Wiki pages and a mailing list.

Things You Might Need to Know about Tclhttpd

There is a custom/ directory whose contents is sourced into tclhttpd at startup. You can add stuff in there.

The startup file is called httpd.tcl, and sources httpdthread.tcl and uses tclhttpd.rc - where they're installed depends upon your distribution and installation choices.


Meir

I'd like to learn tcl/tk well, especially for Web-based programming. Had done so till now in PHP. I'm reading Brent Welch's fine book.

Well, I got tclhttpd installed on my WIN2000 box. But I can't get my small source file (x.tcl) to run in the browser. It lets me go as far as "httpd://localhost:8015".

Do I need to declare a "virtual directory" in tclhttpd as I would in WIN2000's IIS? Can you tell me how I "point" my browser to my tiny source file that contains not much more than [clock format [clock seconds]]]? I'd appreciate your help.

P.S. I've read some literature the httpd home page offers, but - frankly - it's more like Chinese to me. It seems the people "into" this technology just can't explain it well enough to guys like me who, unfortunately, were made stupid and straighjacketed by Microsoft point-and-shoot dumbed-down simplicity. If you could hold my hand a bit - I'd be grateful.

Jeff Smith I am no expert but email me the file and I will try to get it to work for you.


Meir Thanks Jeff; It's not the file that's the problem; It's no more than: puts "The time now is: [clock format [clock seconds]]]" It's getting my browser to access my source.

For example, on WIN2000(IIS) & PHP, I create a "virtual directory" in IIS, e.g. "MyVirtual", then in the browser use that name as part of the URL to "get to" my script eg., "http://localhost/MyVirtual/test.php ". But for tclhttpd - I'm lost. I only got as far as my browser "recognizing" httpd://localhost:8015.

Much obliged, thanks.

Jeff Smith The easiest way to achieve this is to create a file called x.tml and place it in the htdocs directory. In the file put the following

 [Doc_Dynamic]

 The time now is: [clock format [clock seconds]]

Then point your browser to http://localhost:8015/x.html or http://localhost:8015/x.tml

Does this help? Feel free to ask again!


LES: I also didn't find the documentation very clear. And the "need to get tclhttpd up and running before you can read the manuals" (stated above) reminds me of those funny candy containers that are hard to open and bring the opening instructions... on the inside.


Meir

Yipee; It worked. Thanks a lot Jeff;

I'm left puzzled however; Why does the following code work

The time now is: [clock format [clock seconds]]]

...and were I to write

puts "The time now is: [clock format [clock seconds]]]"

...I get

puts "The time now is: Tue Nov 29 9:17:33 AM Eastern Standard Time 2005"

...Why is the tcl command "puts" ignored? How can I code in tcl when some of my commands "take" and others don't ???


MG This is only a guess, but it seems whatever routines are used for parsing the Tcl only parse what's inside square brackets, and print the rest out as text verbatim. So, instead of

  puts "The time now is: [clock format [clock seconds]]"

try using

  [puts "The time now is: [clock format [clock seconds]]"

Meir

Come on MG - That makes no sense; And bracketing the code doesn't work anyhow!


Jeff Smith In TclHttpd there are numerous ways to achieve the same result. In this example I used what is known as the Template system. From the TclHttpd documentation "The template system uses HTML pages that embed Tcl commands and Tcl variables references. The server replaces these using the subst command and returns the results." Therefore to make the above example output in bold

 [Doc_Dynamic]

 <B>The time now is: [clock format [clock seconds]]</B>

So when you use the template system, as MG suggested, you need to enclose all your Tcl commands in square brackets. However the puts command sends its output to stdout by default not to the socket the browser is communicating over. So

 [puts "The time now is: [clock format [clock seconds]]"]

displays a blank page in the browser. However if you have started TclHttpd from the command line you can actually see that the output has gone to stdout

 can't find package limit
 Running with default file descriptor limit
 /debug user "debug" password "2hjbgan2frdy"
 httpd started on port 8015

 The time now is: Wed Nov 30 08:58:58 EST 2005

This is handy to know when your debugging.