mirror of
https://github.com/janet-lang/janet
synced 2025-02-05 11:40:00 +00:00
![Calvin Rose](/assets/img/avatar_default.png)
This also changes the api of servers slightly - in light of having support for ev tasks, it is probably better to remove the "simple" server code and replace it with some Janet or remove it all together. While convenient, it has issues with error handling and rigidity.
16 lines
359 B
Clojure
16 lines
359 B
Clojure
(defn handler
|
|
"Simple handler for connections."
|
|
[stream]
|
|
(defer (:close stream)
|
|
(def id (gensym))
|
|
(def b @"")
|
|
(print "Connection " id "!")
|
|
(while (:read stream 1024 b)
|
|
(printf " %v -> %v" id b)
|
|
(:write stream b)
|
|
(buffer/clear b))
|
|
(printf "Done %v!" id)
|
|
(ev/sleep 0.5)))
|
|
|
|
(net/server "127.0.0.1" "8000" handler)
|