Created
September 21, 2012 09:02
-
-
Save stingh711/3760481 to your computer and use it in GitHub Desktop.
A simple UDP server in clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import '(java.net DatagramSocket DatagramPacket)) | |
(def socket (DatagramSocket. 5200)) | |
(def running (atom true)) | |
(def buffer (make-array Byte/TYPE 1024)) | |
(defn parse [packet] | |
(println (String. (.getData packet) 0 (.getLength packet)))) | |
(defn start-receiver [] | |
(while (true? @running) | |
(let [packet (DatagramPacket. buffer 1024)] | |
(do | |
(println "running") | |
(.receive socket packet) | |
(future (parse packet)))) | |
) | |
) | |
(start-receiver) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment