Answer a GET request with two chunks of data sent 2 seconds apart

47 views
Skip to first unread message

MHOOO

unread,
Jul 30, 2011, 12:19:22 PM7/30/11
to Compojure
Hello everybody,

I'd like to implement the server side of Google Closure's
BrowserChannel. For this however I need to be able to answer to a GET
request with two chunks of data, which are being sent 2 seconds apart.
Basically something like the following:
- User U sends GET request to Server S
- S receives GET request from U, accepts it and writes "11111" back to
U *without closing the connection*
- S waits 2 seconds
- S writes "2" back to U
- S closes the GET connection
- U receives the data

Anyone has a idea how I could achieve this with compojure?

James Reeves

unread,
Jul 30, 2011, 2:56:05 PM7/30/11
to comp...@googlegroups.com

You could use a lazy seq, e.g.

(lazy-seq
(cons "11111"
(do (Thread/sleep 2000)
(list "2"))))

- James

MHOOO

unread,
Jul 30, 2011, 9:10:41 PM7/30/11
to Compojure
For some reason that does not work: Is the lazy-seq possibly being
realized before sent (element by element) to the client?

On Jul 30, 8:56 pm, James Reeves <jree...@weavejester.com> wrote:

James Reeves

unread,
Jul 31, 2011, 8:38:46 AM7/31/11
to comp...@googlegroups.com
On 31 July 2011 02:10, MHOOO <thomas....@googlemail.com> wrote:
> For some reason that does not work: Is the lazy-seq possibly being
> realized before sent (element by element) to the client?

It looks like you need to wrap the ending seq in a lazy-seq too. This
worked for me:

(GET "/" []
(lazy-seq
(cons
"11111"
(lazy-seq
(do (Thread/sleep 2000)
(list "2"))))))

- James

MHOOO

unread,
Jul 31, 2011, 9:58:44 AM7/31/11
to Compojure
Ah, great - that worked.

Many thanks!

On Jul 31, 2:38 pm, James Reeves <jree...@weavejester.com> wrote:

Eric Lavigne

unread,
Aug 6, 2011, 9:48:24 AM8/6/11
to comp...@googlegroups.com

I'd like to implement the server side of Google Closure's
BrowserChannel. 

Just noticed a thread on the closure-library-discuss mailing list that may be helpful for this effort.

A couple days ago, David Turnbull <dtur...@gmail.com> announced a Ruby implementation of the server side of BrowserChannel.



The source code is short and readable, and a translation to Clojure may be easier than writing from scratch.
Reply all
Reply to author
Forward
0 new messages