Discussion:
Aleph websocket server that handles requests in a loop
Moiz
2016-03-21 08:15:24 UTC
Permalink
What I need to implement isnt out of the ordinary, but I need some help
doing it with Manifold streams. I am porting a service of ours that
currently runs on http-kit (websockets). I essentially need to write the
"on-receive" handler (of http-kit) with aleph. So I understand that the
'webcoket-connection' fn returns a deferred which yields a duplex stream.
But I could not find much info anout how to use the duplex stream. Do I
need to loop infinitely and keep calling take! on the stream, then process
data, and then call put! to send data to client? Is there a standard way to
do this?

Also, what would be the equivalent of http-kit's "on-close" with Aleph? In
other words, how do I get notified when the client closes the websocket
connection?

Here's a standard example of http-kit (websocket)

(defn handler [request]
(with-channel request channel

(ctl/info "client connected")

(on-close channel (fn [status] (println "client close it" status)))
(on-receive channel (fn [data]

(send! channel (process-request data))))))
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Moiz
2016-03-21 10:50:01 UTC
Permalink
I think I found the answers (by reading sources of the stream namespace).
The "on-closed" and "consume" functions were what I needed. If anyone has
more info to add to this topic, please feel free.

Thanks,
Moiz
Post by Moiz
What I need to implement isnt out of the ordinary, but I need some help
doing it with Manifold streams. I am porting a service of ours that
currently runs on http-kit (websockets). I essentially need to write the
"on-receive" handler (of http-kit) with aleph. So I understand that the
'webcoket-connection' fn returns a deferred which yields a duplex stream.
But I could not find much info anout how to use the duplex stream. Do I
need to loop infinitely and keep calling take! on the stream, then process
data, and then call put! to send data to client? Is there a standard way to
do this?
Also, what would be the equivalent of http-kit's "on-close" with Aleph? In
other words, how do I get notified when the client closes the websocket
connection?
Here's a standard example of http-kit (websocket)
(defn handler [request]
(with-channel request channel
(ctl/info "client connected")
(on-close channel (fn [status] (println "client close it" status)))
(on-receive channel (fn [data]
(send! channel (process-request data))))))
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...