* is Unix

Jacob Kaplan-Moss

October 7, 2009

Ryan’s I like Unicorn because it’s Unix appears to have started a mini-meme of folks writing simple forking network servers in their language of choice. I’m really enjoying reading ‘em — they’re a sort of Rosetta Stone of network code — so I’m going to keep a running list of links here. Tell me about any I’ve missed (via email, comments, or twitter) and I’ll add ‘em to the list.

Comments:

Henrique:

The SocketServer version is s-w-e-e-t.

Russell Beattie:

This is actually pretty educational for me. I implemented the sample in PHP using your Python version as a start (as I don't really know Ruby):

http://pastebin.com/f3ad81c27

It works fine, except that I can't seem to trap Ctl-C, which I'm not sure is a bug or that I'm not using the signal traps correctly.

Thanks for collecting the posts!

-Russ

jinjing:

very interesting :) here's a haskell one

http://gist.github.com/204859

Mark Edgar:

Your SocketServer version is not pre-forking.
You can have a pre-forking server with SocketServer. Instead of using ForkingTCPServer, just use TCPServer and then fork a few times, having each child call serve_forever().

Henk Punt:

Stackless Python / Concurrence based one (not forking, not threading, but light-weight tasking...(async/epoll under the hood):
http://opensource.hyves.org...

Kaspars Foigts:

Russell Beattie, PHP signals are not working correctly, since first socket_accept is blocking all other stuff. If you press Ctrl+C and then try to establish connection, you'll see script exiting immediately, since connection has been accepted and now PHP can continue with its ticks.

I implemented my own version, but you were first to publish it here :)

teeler:

Ocaml! http://gist.github.com/205407
May not be exemplary, but it's pretty simple.

Leave a comment:

Use your real name, or risk deletion.

Optional.

No markup allowed. Linebreaks will be converted; links will be linkified.

Be nice; don't be that guy.