Created
March 28, 2011 14:21
-
-
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
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
| (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