2-way fetch over websockets?

103 views
Skip to first unread message

Frank Siebenlist

unread,
Oct 25, 2012, 2:54:37 AM10/25/12
to clj-...@googlegroups.com
Did anyone work on a fetch implementation over websockets?

My hope was to have a fetch implementation that works in both ways, i.e. also from the server calling into the browser.

Is that feasible?

Thanks, FrankS.

Martin Clausen

unread,
Oct 25, 2012, 3:28:13 AM10/25/12
to clj-...@googlegroups.com
I have not seen any such work, but it does sound like it could be very useful.

Chris Granger

unread,
Oct 25, 2012, 1:14:32 PM10/25/12
to clj-...@googlegroups.com
it's certainly possible. I didn't do it primarily because websockets are often far more trouble than they're worth - though things have gotten better in the past little bit. The main thing that's annoying is that in order to do it, you *have* to use server vendor specific features that haven't been generalized by something like ring.

Cheers,
Chris.

Frank Siebenlist

unread,
Oct 25, 2012, 2:30:40 PM10/25/12
to clj-...@googlegroups.com, Frank Siebenlist
Interesting.

I was looking for a 2-way fetch after digging thru the cljs-repl code, which is not a very flexible setup.

If you would have the 2-way fetch over web sockets, then you could "easily" add repl-like features to your running cljs-js environment without having to run an additional dedicated custom repl-server.

You could send compiled-cljs-code as js for eval to the browser thru a fn-call,
driving your cljs-js app thru calls in you clj-server,
introspect your js-vm thru fetch fn-calls,
call from your js-vm thru fetch to introspect your cljs-vars, docs, ns,
truly run a repl inside of your browser's js-vm, sending repl-forms to clj-server for compilation and eval'ing the returned js-code (you could do that with the current one-way fetch…),
implement a more flexible interactive repl that would ride on a ring-middleware and would add authN/ssl support,
…keep dreaming…

-FrankS.

Roman Yakovlev

unread,
Oct 31, 2012, 11:05:37 AM10/31/12
to clj-...@googlegroups.com
+1 for that will be very handy.
What about other things ? like server sent events also hard to impliment ?

 

четверг, 25 октября 2012 г., 21:14:33 UTC+4 пользователь Chris Granger написал:

Roman Yakovlev

unread,
Nov 1, 2012, 8:19:37 AM11/1/12
to clj-...@googlegroups.com
I investigated the question and here is there result.
There is a project called noir-async. It's using aleph project - async commication for clojure . Pretty complex stuff i could say but it does the work. You can also check example app built on noir-async - noir-async-chat.
I think it's work in progress and there should be better and easier implementations of that stuff. defsocket maybe ? remotesocket ?

четверг, 25 октября 2012 г., 10:54:37 UTC+4 пользователь Frank Siebenlist написал:

Frank Siebenlist

unread,
Nov 1, 2012, 12:14:36 PM11/1/12
to clj-...@googlegroups.com, Frank Siebenlist
Thanks Roman.

I've been playing with noir-async and noir-async-chat, and they were very easy to work with - nice examples of how to move to a truly async style of processing.

It seems that that could be a good building stone to get fetch implemented over web sockets.

-FrankS.

PS. I had to update the noir-async-chat's project.clj to make it work with the latest and greatest:

(defproject noir-async-chat "1.0.0-SNAPSHOT"
:main noir-async-chat.server
:description "An example using noir-async"
:dependencies [[org.clojure/clojure "1.4.0"]
[noir-async "1.1.0-beta10"]
[cheshire "4.0.3"]])

Chris Granger

unread,
Nov 1, 2012, 1:47:43 PM11/1/12
to clj-noir, Frank Siebenlist
Just using noir on top of aleph is far simpler than that would imply :) Here's a gist I did once upon a time ago showing it: https://gist.github.com/1257857

Cheers,
Chris.

Andrew Cholakian

unread,
Nov 1, 2012, 1:54:10 PM11/1/12
to clj-...@googlegroups.com
Yep, just using aleph is quite simple in principle, but I'll just point out the reason I wrote noir-async: the edge cases are tricky, esp. if you're trying to support both HTTP churnked and web sockets (for unidirectional) streaming. Straight aleph is more verbose.

Additionally, using straight aleph requires you to learn aleph. While I love aleph (it's probably my favorite clojure library), it really is a universe unto itself, and more than most people need for sending / receiving web socket messages.

Lastly, you can get at all the aleph stuff you need in noir-async, no need to worry about painting yourself into a corner. The aleph connection objects are hidden in the bound 'conn' variable in the examples for use with lower level stuff.

-- Andrew

Roman Yakovlev

unread,
Nov 4, 2012, 11:29:10 AM11/4/12
to clj-...@googlegroups.com
I found easiest way with Pusher.com. There is clj-pusher lib to use as interface to pusher service ( publish subscribe model) also you need some js or cljs code in client and that's all needed to make your site realtime. 

2tothe8th

unread,
Nov 16, 2012, 5:12:35 PM11/16/12
to clj-...@googlegroups.com
Thanks for the pusher recommendation.  I've seen that before.  That looks cool.

David
Reply all
Reply to author
Forward
0 new messages