Skip to content

Instantly share code, notes, and snippets.

Created October 5, 2009 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/202551 to your computer and use it in GitHub Desktop.
Save anonymous/202551 to your computer and use it in GitHub Desktop.
(import '(java.net ServerSocket Socket InetAddress))
(use '[clojure.contrib.duck-streams :only (reader spit)])
(defn handle-request [sock]
(let [is (.. sock getInputStream)
os (.. sock getOutputStream)]
(with-open [rdr (reader is)]
(println (line-seq rdr)))))
(defmulti http-listen class)
(defmethod http-listen ServerSocket [socket]
"Bind to a socket and keep listening"
(let [client-socket (.. socket accept)]
(handle-request client-socket))
(recur socket))
(defmethod http-listen Integer [port]
"Takes a port number to listen on"
(http-listen (ServerSocket. port)))
(http-listen 8081)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment