Skip to content

Commit 0e96ffe

Browse files
committed
WebSocket running next to dynamically generated content as well as
static files, in other words server is ready for a client to arrive.
0 parents  commit 0e96ffe

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pom.xml
2+
*jar
3+
/lib/
4+
/classes/
5+
.lein-failures
6+
.lein-deps-sum

README

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# ws-cljs
2+
3+
WebSocket & ClojureScript repository.
4+
5+
## License
6+
7+
Copyright (C) 2011 FIXME
8+
9+
Distributed under the Eclipse Public License, the same as Clojure.

project.clj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(defproject ws-cljs "0.1-SNAPSHOT"
2+
:description "WebSocket and ClojureScript gitorial"
3+
:main "ws-cljs.core"
4+
:dependencies [[org.clojure/clojure "1.2.1"]
5+
[aleph "0.2.0-alpha2"]
6+
[compojure "0.6.5"]
7+
[hiccup "0.3.6"]]
8+
:dev-dependencies [[slamhound "1.2.0"]])

src/ws_cljs/core.clj

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
(ns ws-cljs.core
2+
(:use [aleph.http :only [start-http-server wrap-aleph-handler wrap-ring-handler]]
3+
[compojure.core :only [GET defroutes]]
4+
[hiccup.page-helpers :only [html5 include-js]]
5+
[lamina.core :only [channel map* receive siphon]]
6+
[ring.middleware.file :only [wrap-file]])
7+
(:require [compojure.route :as route]))
8+
9+
(def broadcast-channel (channel))
10+
11+
(defn chat-handler [ch handshake]
12+
(println "Connected " handshake)
13+
(receive ch
14+
(fn [name]
15+
(println "Hello " name)
16+
(siphon (map* #(str name ": " %) ch) broadcast-channel)
17+
(siphon broadcast-channel ch))))
18+
19+
(defn layout [& content]
20+
(html5 [:head [:title "new page"] (include-js "js/ws-control.js")]
21+
[:body content]))
22+
23+
(defroutes my-app
24+
(GET "/" [] (layout [:p "awesome!"]))
25+
(GET "/socket" [] (wrap-aleph-handler chat-handler))
26+
(route/not-found (layout [:p "aww... this doesn't exist"])))
27+
28+
(defn -main []
29+
(start-http-server (-> my-app
30+
(wrap-file "html")
31+
wrap-ring-handler) {:port 8080 :websocket true})
32+
(println "server started"))
33+

test/ws_cljs/test/core.clj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(ns ws-cljs.test.core
2+
(:use [ws-cljs.core])
3+
(:use [clojure.test]))
4+
5+
(deftest replace-me ;; FIXME: write
6+
(is false "No tests have been written."))

0 commit comments

Comments
 (0)