Skip to content

Instantly share code, notes, and snippets.

@RKushnir
Created April 3, 2013 12:30
Show Gist options
  • Save RKushnir/5300764 to your computer and use it in GitHub Desktop.
Save RKushnir/5300764 to your computer and use it in GitHub Desktop.
(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