-
-
Save lukaszkorecki/7ce1653dda318112c8f059ca9e138fe2 to your computer and use it in GitHub Desktop.
A simple UDP server in clojure
This file contains hidden or 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