Skip to content

sinclairday/aleph

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aleph is a framework for asynchronous communication, built on top of Netty. It can do all kinds of things, including:

HTTP Server

Aleph conforms to the interface described by Ring, with one small difference: the request and response are decoupled.

(use 'aleph.core 'aleph.http)
	
(defn hello-world [channel request]
  (enqueue channel
    {:status 200
     :headers {"content-type" "text/html"}
     :body "Hello World!"}))

(start-http-server hello-world {:port 8080})

HTTP Client

This snippet prints out a never-ending sequence of tweets:

(use 'aleph.core 'aleph.http)
	
(let [ch (:body
           (sync-http-request
             {:method :get
              :basic-auth ["aleph_example" "_password"]
              :url "http://stream.twitter.com/1/statuses/sample.json"}))]
  (doseq [tweet (lazy-channel-seq ch)]
    (println tweet)))

A more in-depth exploration of this example can be found here.

WebSocket

Making a simple chat client is trivial. In this, we assume that the first message sent by the client is the user’s name:

(use 'aleph.core 'aleph.http)

(def broadcast-channel (channel))

(defn chat-handler [ch handshake]
  (receive ch
    (fn [name]
       (receive-all ch #(when % (enqueue broadcast-channel (str name ": " %))))
       (siphon broadcast-channel ch))))

(start-http-server chat-handler {:port 8080 :websocket true})

TCP Client/Server

Here is a basic echo server:

(use 'aleph.core 'aleph.tcp)
	
(defn echo-handler [channel client-info]
  (siphon channel channel))

(start-tcp-server echo-handler {:port 1234})

Other protocols are supported, and still more are forthcoming.

Aleph is meant to be a sandbox for exploring how Clojure can be used effectively in this context. Contributions and ideas are welcome.

A mailing list can be found here, and API documentation here.

About

a framework for asynchronous communication

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published