Wednesday, July 5, 2017

Django channels for single user

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.

--
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-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/269c3144-280e-4e65-8ab2-38a208e08dd2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment