Created
October 5, 2009 22:24
-
-
Save anonymous/202551 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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