send django channels 2 messages to an individual user who might have more than one browser tab or device connected

430 views
Skip to first unread message

Levent Engin

unread,
Feb 12, 2020, 2:03:24 PM2/12/20
to django...@googlegroups.com
Hi all.
I want to send Channels2  messages to an individual user who might have more than one browser tab or device connected.  How can I do that. In documents it is said that "group_send"  structure  can be used. how can i implement that?  Is there a sample code for this?

Best  Regards.

Levent

Andréas Kühne

unread,
Feb 14, 2020, 3:08:39 AM2/14/20
to django...@googlegroups.com
Regardless of how the user is connected - if you send a django channels message to the user - you will send it to all connected devices.

Regards,

Andréas


--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANQNAiS6-CY2%3D2qDmc3Mcv7icKGLH0H4Hmm7ox0KVoc_L3HE%3DA%40mail.gmail.com.

Levent Engin

unread,
Feb 26, 2020, 4:40:10 AM2/26/20
to django...@googlegroups.com, Andréas Kühne
Hi Andreas;

The  Channels2   system that we are using is for connecting  couriers to their working  customers.   This is planned to be a large system using Channels2, which is in pilot phase now.

When a  courier is connected to  channels we create a a database filed to keep the user_name and channel_name and when disconnected to delete.   We do the same for customers but customers might be connected from many browsers and mobile devices (more than one connection).  So we send the data ( ws message containing location) coming from couriers  to the actual customer connections in a while loop  using  "channel_layer.send"  -  one for each .

I have two questions:
1.  Is the sending method used convenient, or should i change it to create a group for customers by  user name and use group_send   to them.  Which one is better technically?  I see that sometimes channel fails (can be wifi - internet failure ) but  systems does not close and it persist as data in database so the system tries to send data to non existing channel.  Is there a mechanism to check if that channel exists  at the moment?
2. This is planned to be a large system   which will contain 3-4 thousand couriers and hundreds of customers (with more than one connections).   Which tools should we use as data load increases?   Is there a documentation for that?

We use:
channels==2.3.1
channels-redis==2.4.1
Django==2.2.4
Python 3.6.9


BR

Levent



Andréas Kühne <andrea...@hypercode.se>, 14 Şub 2020 Cum, 11:08 tarihinde şunu yazdı:

Andréas Kühne

unread,
Feb 26, 2020, 4:51:15 AM2/26/20
to django...@googlegroups.com
First of all - if you are writing something new - use the latest versions of everything. You shouldn't develop for django 2.2 now - but rather 3.0. The same goes for python and django channels. Make sure you start with the latest versions of everything.

Django won't be the issue for what you are proposing. You need to make sure that you can handle everything in the infrastructure. websockets puts stress mainly on the http servers - in apache you need a thread per connected websocket. So the issue isn't the django part, but rather you infrastructure as a whole.

Regards,

Andréas

Reply all
Reply to author
Forward
0 new messages