pedestal

Fabim 2021-07-03T13:34:37.044Z

I am using the official pedestal web-socket example code. How do I retrieve the send-ch when the client closes the connection? Unfortunately the :on-close of ws-path only has a num-code and not the ws-session and the send-ch like the :on-connect https://github.com/pedestal/pedestal/blob/a72c7a274af0e60ba42a18d859f7c6fe9314130e/samples/jetty-web-sockets/src/jetty_web_sockets/service.clj#L61

souenzzo 2021-07-05T13:27:13.046Z

A practical response: You don't need to implement close methods You will always need an ping method, to find disconnected clients (due no-internet or something like) In this ping routine, you will close/cleanup the closed channels

Fabim 2021-07-05T13:29:03.046200Z

Ah interesting, thanks. Makes sense, I was assuming I can rely on a on-close message.

souenzzo 2021-07-05T13:43:54.046400Z

Another close trigger is when you are writing a response but it throws a "closed stream" error. I worked with websockes about 4 years ago, I don't remember everything well. But as far I remember, most of our sockets close came from write errors

souenzzo 2021-07-03T15:24:55.044200Z

Hey Fabim After study a bit the interface, I see that even on jetty we don't have the instance. I believe that this is because when the close event occours, the Session already do not exists anymore. For advanced usages, you can take a look at listener-fn and make-ws-listener https://github.com/pedestal/pedestal/blob/master/jetty/src/io/pedestal/http/jetty/websockets.clj#L125

Fabim 2021-07-03T16:21:16.044500Z

@souenzzo Thanks for your answer. Since the session is not returned, it’s hard to find the corresponding send-ch and to close it. I’m curious if there is a good way of cleaning up the connections at :on-close (ideally using interceptors). Other web-socket solutions like chord.http-kit send a message on close, but I’m not sure how to integrate them in the pedestal ws-routing.