Created
April 3, 2013 12:30
-
-
Save RKushnir/5300764 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
(ns listener | |
(:require [clojure.java.io :as io]) | |
(:import [java.net ServerSocket Socket]) | |
(:import [java.io InputStreamReader BufferedReader])) | |
(def settings {:client-port 5000}) | |
(defn get-reader [socket] | |
(BufferedReader. (InputStreamReader. (.getInputStream socket)))) | |
(defn accept-client [server-socket] | |
(with-open [client-socket (.accept server-socket) | |
reader (get-reader client-socket)] | |
(println (. reader readLine)))) | |
(defn accept-clients [server-socket] | |
(repeatedly #(accept-client server-socket))) | |
(defn start-server [port] | |
(with-open [socket (new ServerSocket port)] | |
(dorun (accept-clients socket)))) | |
(start-server (:client-port settings)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment