Skip to content

Instantly share code, notes, and snippets.

@lukaszkorecki
Forked from stingh711/receiver.clj
Created June 6, 2017 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukaszkorecki/7ce1653dda318112c8f059ca9e138fe2 to your computer and use it in GitHub Desktop.
Save lukaszkorecki/7ce1653dda318112c8f059ca9e138fe2 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