Skip to content

Instantly share code, notes, and snippets.

@stingh711
Created September 21, 2012 09:02
Show Gist options
  • Save stingh711/3760481 to your computer and use it in GitHub Desktop.
Save stingh711/3760481 to your computer and use it in GitHub Desktop.
A simple UDP server in clojure
(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