2

Day 7: An echo server in Clojure

 3 years ago
source link: https://jvns.ca/blog/2013/10/09/day-7-an-echo-server-in-clojure/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Day 7: An echo server in Clojure



Today I spent some time on a fun kernel module, but it is not working yet! So here is what I also did.

It did not take very long and I didn’t really learn too much Clojure doing this – this is really just procedural code written in Clojure. I can’t tell yet if this is an appropriate way to write a small Clojure program. Need to get some code review on this.

But it works! You can see the code here: https://gist.github.com/jvns/6910896

You can interact with the server using netcat (see also: Day 2: netcat fun!). The -u option here tells netcat to use UDP instead of TCP.

bork@kiwi ~/w/h/clorrent> nc -u localhost 12345
Hi, Clojure!
Hi, Clojure!

If you don’t want to set up a whole Leinengen project to run this, you can use lein-exec.

This is the first step towards maybe writing a BitTorrent client in Clojure – many other people are writing BitTorrent client and really enjoying it, and I’m jealous. We’ll see if it happens!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK