2020-02-10 01:04:34 +00:00
|
|
|
(defn handler
|
|
|
|
"Simple handler for connections."
|
|
|
|
[stream]
|
2020-07-07 00:13:32 +00:00
|
|
|
(defer (:close stream)
|
|
|
|
(def id (gensym))
|
|
|
|
(def b @"")
|
|
|
|
(print "Connection " id "!")
|
|
|
|
(while (:read stream 1024 b)
|
|
|
|
(repeat 10 (print "work for " id " ...") (ev/sleep 1))
|
|
|
|
(:write stream b)
|
|
|
|
(buffer/clear b))
|
|
|
|
(printf "Done %v!" id)))
|
2020-05-31 20:46:01 +00:00
|
|
|
|
|
|
|
# Run server.
|
2020-07-07 00:13:32 +00:00
|
|
|
(let [server (net/server "127.0.0.1" "8000")]
|
|
|
|
(print "Starting echo server on 127.0.0.1:8000")
|
2020-07-20 00:41:12 +00:00
|
|
|
(forever
|
|
|
|
(if-let [conn (:accept server 2.8)]
|
|
|
|
(ev/call handler conn)
|
|
|
|
(print "no new connections"))))
|