mirror of
https://github.com/janet-lang/janet
synced 2024-11-19 23:24:49 +00:00
20 lines
403 B
Plaintext
20 lines
403 B
Plaintext
(defn handler
|
|
"Simple handler for connections."
|
|
[stream]
|
|
(def id (gensym))
|
|
(def b @"")
|
|
(print "Connection " id "!")
|
|
(while (:read stream 1024 b)
|
|
(:write stream b)
|
|
(buffer/clear b))
|
|
(printf "Done %v!" id))
|
|
|
|
(print "Starting echo server on 127.0.0.1:8000")
|
|
|
|
(def server (net/server "127.0.0.1" "8000"))
|
|
|
|
# Run server.
|
|
(while true
|
|
(with [conn (:accept server)]
|
|
(handler conn)))
|