Version 8 of 8-Line Server

Updated 2009-05-29 11:03:45 by suchenwi

jdp - An 8 line server. Serves text files out of, or below, the current directory. As no headers are sent, it depends on the browser what he does with it - IE6 seems to expect HTML 0.9 (i.e. linebreaks are ignored, etc.)

proc s {c a p} {
        set o [lindex [split [gets $c] " "] 1]
        puts $c [read [set f [open ".$o"]]]
        close $f
        close $c
set s [socket -server s 3210]
vwait forever

jdp - After spending time in the chatroom, with the help of stu and suchenwi, it became a 1-line, 140-char server. (Interactive mode only, though.)

vw [soc -server {appl {{c a p} {puts $c [read [set f [open .[regsub {\.\.+} [lindex [split [gets $c] \ ] 1] x]]]][close $f];close $c}}} 80]

RS 2009-05-29: The fcopy version is still a few bytes shorter:

vw [soc -server {appl {{c a p} {fcopy [set f [open .[regsub {\.\.+} [lindex [split [gets $c] \ ] 1] x]]] $c;close $f;close $c}}} 80]

In fact, I'm pretty sure the split isn't needed, as {} etc can't occur in URLs. Down to 121 characters:

vw [soc -server {appl {{c a p} {fcopy [set f [open .[regsub {\.\.+} [lindex [gets $c] 1] x]]] $c;close $f;close $c}}} 80]

Category Example