Flagrant self promotion ahead -

I wrote a wrapper library for JBoss Netty, an asynchronous web
application library for Java, which seems to do exactly what you are
looking for.

http://www.github.com/texodus/saturnine

No main loop, event driven, synch, etc.  It's pretty easy (imo) to
utilize Clojure's concurrency primitives to keep state across multiple
connections, or you can simply return the updated state value for each
event handler's functions.

In saturnine.examples namespace, theres a trivial example of such an
implementation named Chat, using an atom and the saturnine session
management:

(defn- write-all
  [users msg]
  (doseq [user (vals (dissoc users (get-ip)))]
    (write user (str (get-ip) " : " msg))))

(defhandler #^{:doc
  Chat [users]
  (connect    [_] (do (dosync (alter users assoc (get-ip) (get-
connection)))
                      (write-all @users "User connected!\r\n")))
  (disconnect [_] (do (dosync (alter users dissoc (get-ip)))
                      (write-all @users "User disconnected!\r\n")))
  (upstream   [_ msg] (do (write-all @users msg))))

(defn start-chat-server
  []
  (start-server 3333 :string :print (new Chat (ref {}))))


On Apr 19, 3:45 am, Chris Riddoch <[email protected]> wrote:
> I'd like to call on the collective wisdom of the group to help me with
> a project I've come up with (partly) for the purpose of understanding
> Clojure's parallelism & synchronization primitives.
>
> Imagine a library that both creates and accepts network sockets,
> acting like a simple proxy, forwarding data in both directions.  It
> would provide hooks for intermediate processing of data in both
> directions.  But don't just think "web proxy" -- my main purpose is to
> allow for better testing of *any* given networking protocol.
> Specifically, to log the interactions, replay either side of the
> communication to simulate any system too complicated to mock, do
> fuzz-testing in the middle of the stream for security testing... that
> sort of thing.  (Simple protocol logging with timestamps is the first
> task I have in mind.)
>
> To better my understanding, I'd like to use a design that requires no
> explicit main event loop in my code, and exposes me to functional
> techniques.   I suspect the result will look a little like the various
> libraries such as Ruby's IO::Reactor, Perl's POE, or Python's Twisted.
> But I also suspect that Clojure's unique features will make this a lot
> easier.
>
> Here's where I'm stuck: I don't quite understand how to use Clojure's
> parallelization and synchronization primitives for solving this kind
> of problem -- I understand the designs for ordinary servers quite a
> lot better than those for proxies.
>
> I'd  appreciate pointers to documents about this, but I especially
> want to inspire some discussion of what would be idiomatic clojure for
> an event-driven asynchronous-I/O application like the one I'm
> describing.
>
> Please help me design!
>
> --
> Chris Riddoch
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group 
> athttp://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to