You want to look for incoming data on the "websocket.receive" channel, which will call you once per message you send down with the right data. That's "websocket.connect", which happens after the socket opens but before data is sent down it.
Andrew
On Wed, Aug 30, 2017 at 10:07 AM, Samuel Muiruri <muiruri.samuel@gmail.com> wrote:
--I have this javascript code that send data to channels
// Note that the path doesn't matter for routing; any WebSocket // connection gets bumped over to WebSocket consumers socket = new WebSocket("ws://" + window.location.host + "/chat/"); socket.onmessage = function(e) { alert(e.data); } socket.onopen = function() { socket.send({"test":"data"}); } // Call onopen directly if socket is already open if (socket.readyState == WebSocket.OPEN) socket.onopen();
I'm curios how from
message
I can get the json{"test":"data"}
here's the view
# Connected to websocket.connect @channel_session def ws_connect(message, key): # Accept connection message.reply_channel.send({"
accept": True}) if i try message.content['test'] I get a key error key = message['test']File "/usr/local/lib/python2.7/dist-packages/channels/ message.py", line 36, in __getitem__ return self.content[key]KeyError: 'test'--Best Regards,Samuel Muiruri.Web Designer
| +254 738 940064
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/CAJZFZXpbC% .2BZ9xSWumRVALKMnt29DkTLchUtKBv kBJyXBh43nQw%40mail.gmail.com
For more options, visit https://groups.google.com/d/optout .
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/CAFwN1uoKYptiSAbwfGnUQ-QNbO-M33%3D%3DVm%3D8pv03Agmfh%3DPrpw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment