Version 5 of 8-Line Server

Updated 2009-05-29 07:27:13 by suchenwi

jdp - An 8 line server. Serves text files out of the current directory.

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:

% 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