Skip to content

Commit

Permalink
Echo server
Browse files Browse the repository at this point in the history
  • Loading branch information
francois committed Dec 13, 2008
0 parents commit 91a1347
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions rpn.clj
@@ -0,0 +1,25 @@
(def socket (java.net.ServerSocket. 5001))

(defn make-reader [in-stream]
(java.io.InputStreamReader. in-stream))

(defn make-writer [out-stream]
(java.io.OutputStreamWriter. out-stream))

(defn process [socket]
(let [ in (java.io.LineNumberReader. (make-reader (. socket getInputStream)))
line (. in readLine)
out (java.io.PrintWriter. (make-writer (. socket getOutputStream)))]
(println "line read:\n\t'" line "'")
(println "Class of line: " (.. line getClass getName))
(. out print "you sent: '")
(. out print line)
(. out println "'")
(. out flush)
(. socket close)))

(defn run []
(println "accepting connections")
(process (. socket accept)))

(run)

0 comments on commit 91a1347

Please sign in to comment.