On Wed, Jan 4, 2017 at 3:22 AM, Utku Gültopu <ugult...@gmail.com> wrote:
> It is for sending fresh data to users. Let's say user A follows users B, C > and D. However, only users A, B and C are online. Then only B's and C's > data should be sent to user A. Because user D's data would be stale. > > I thought of holding online users in a table of two columns, one column is > a foreign key to User table and the other column is that user's reply > channel. I would run a function every minute which would check if the > WebSocket connections attached to reply channels are alive for every user > in this table. > However I couldn't find how I can check if a WebSocket connection of a > reply channel is alive. AFAIK, there isn't a function like 'is_alive'. I > could send a PING to a channel but AFAIK, the reply would arrive at the > 'websocket.receive' consumer. > > So, is there a way to tell if the WebSocket connected to a channel is > alive or not? > Not as part of Channels, since there's enough options and scaling challenges there that it's hard to pick a single strategy everyone would be OK with. Channels' ability to give you correct pairs of `websocket.connect` and `websocket.disconnect` calls is pretty good these days - Daphne continually pings the websocket to see if it's alive, so the only time you won't get a disconnect message for a socket is if daphne dies or the disconnect channel gets full up. Given that, you can probably do alive status with just tracking in those two consumers and an expiry time for the 0.1% that don't get disconnects through properly. If you want something more robust and more demanding of resources, you can instead make the client application just send something down the socket every 20 seconds to say it's alive and then handle it in the receive consumer instead. Andrew -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFwN1uo%2BF7vrjmE3%3DOQsC%2BwUzO%2Bqf4T_87DKC%3DRUgmZEesXBqA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.