Advertisement
tobotras

Untitled

Apr 22nd, 2024
1,124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns udp.core
  2.   (:import (java.net DatagramSocket DatagramPacket InetAddress NetworkInterface MulticastSocket))
  3.   (:gen-class))
  4.  
  5. (def buf (byte-array 1024))
  6.  
  7. (defn -main []
  8.   (let [server-socket (MulticastSocket. 5353)]
  9.     (doto server-socket
  10.       (.setReuseAddress true)
  11.       (.setNetworkInterface (NetworkInterface/getByName "eth1"))
  12.       (.joinGroup (InetAddress/getByName "224.0.0.251"))
  13.       (.receive (DatagramPacket. buf 1024)))
  14.     (doto (DatagramSocket. 5353)
  15.       (.send (DatagramPacket. buf 1024 (InetAddress/getByName "224.0.0.251") 5353))
  16.       (.close))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement