Django channels for single user

900 views
Skip to first unread message

yingi keme

unread,
Jul 5, 2017, 9:42:57 AM7/5/17
to Django users
How will you create a web socket for a single user such that another program can send a json data to thesame specific user open channel. What i normally see is:

Html script:

var mysocket = new WebSocket('ws://' + window.location.host + '/users/');

routing.py:

channel_routing = [route("websocket.connect", ws_connect),
...

And finally you consumers.py:

def ws_connect(message):
Group('users').add(message.reply_channel)

This is quite the norm for adding a new client to open connection list. But what if you want to send data to a specific client and you dont want to use:

Group('users').send(json_data). As this sends to all clients on the group.

Do you have to create a Group for a every user?

Please i am stuck on this.

Andrew Godwin

unread,
Jul 5, 2017, 10:31:26 AM7/5/17
to django...@googlegroups.com
Yes, you should create a group per user. That way users with more than one tab open will get data sent to all tabs too.

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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@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/269c3144-280e-4e65-8ab2-38a208e08dd2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

yingi keme

unread,
Jul 5, 2017, 11:31:15 AM7/5/17
to django...@googlegroups.com
So how do you create a group for a single user? What is the syntax like?

If you have a site that opens a connection for every user. What is going to be the argument for:

Group(argument).add(message.reply_channel)

Yingi Kem
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

yingi keme

unread,
Jul 5, 2017, 12:20:13 PM7/5/17
to django...@googlegroups.com
Okk. I have tried it. What happens is that
When it starts the HANDSHAKING, it DISCONNECTS. So the websocket doesnt connect.

Any reason why that is happening.?

Yingi Kem

On 5 Jul 2017, at 3:30 PM, Andrew Godwin <and...@aeracode.org> wrote:

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages