I would like to write a simple multiplexing server in Clojure (as a sample project to learn the language) but I am having a very hard time finding resources to aid me in this on the web.
does anyone have any resources that can point to the basics of socket programming in Clojure
and the best way to go about writing such a server?
clojure.contrib.server-socketis your friend. Usecreate-serverlike so to create a simple echo server:Now telnet to make sure it works:
By the way, the server is multithreaded too, because
clojure.contrib.server-socketcreates a new thread on accepting a new connection.If that doesn’t meet your needs, then the Java API is your friend. Since you have full access to Java classes from Clojure, you can just use Java sockets if you need to get down to the metal. I don’t know anything about your background, but assuming you have not used Java sockets before, Sun has a tutorial: http://java.sun.com/docs/books/tutorial/networking/sockets/