I’ll see your simple sockets, and raise you a real server

I had a look at this:

http://www.jadetower.org/muses/archives/000416.html

and thought to myself… hey, I could do that in Tcl in half the code. And it could also handle more than one connection:

proc DoLine {channel} {
    gets $channel line
    puts $channel $line
    flush $channel
}

proc Server {channel clientaddr clientport} {
    fileevent $channel readable [list DoLine $channel]
}

set sk [socket -server Server 6200]
fconfigure $sk -buffering line
fconfigure $sk -blocking 0
vwait forever

I find it more readable as well.

Ruby may well have some good stuff – Rails is very impressive, for instance, and I’m sure Ruby has got lots of other things going for it (like libraries, as the article mentions), but Tcl at its best does things very much the way I like them – simply and elegantly, but without taking away the possibility of doing fancier things should the need arise. Kind of like Rails:-)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s