Skip to content

Instantly share code, notes, and snippets.

@mjul
Created March 28, 2011 14:21
Show Gist options
  • Select an option

  • Save mjul/890544 to your computer and use it in GitHub Desktop.

Select an option

Save mjul/890544 to your computer and use it in GitHub Desktop.
Publish a HTML5 Server-Sent Event to a local Kaazing WebSocket Gateway server via UDP
(ns kaazing-eval.core
(import [java.io File]
[java.net DatagramPacket DatagramSocket InetSocketAddress URI]))
(defn publish [msg]
(let [remote-uri (URI/create "udp://localhost:50505")
remote-addr (InetSocketAddress. (.getHost remote-uri)
(.getPort remote-uri))
socket (DatagramSocket.)]
(let [bytes (.getBytes msg)
packet (DatagramPacket. bytes (count bytes) remote-addr)]
(.send socket packet))))
(comment
;; First, start the Kaazing Web Socket gateway demo on the localhost
;; Open the Server-Sent Events demo in a browser
;; Publish events to the server and watch the browser client update:
(publish "Hello, Kaazing Server-Sent Events from Clojure.")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment