Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. # chat/consumers.py
  2. import json
  3.  
  4. from channels.generic.websocket import WebsocketConsumer
  5. from . import tasks
  6.  
  7. class ChatConsumer(WebsocketConsumer):
  8. def receive(self, text_data):
  9. # Here we receive some data from the client
  10. text_data_json = json.loads(text_data)
  11. message = text_data_json['message']
  12.  
  13. # Here we can process client data and send result back directly
  14. # to the client (by using his unique channel name - `self.channel_name`)
  15. task.process_client_data_in_the_background_and_send_message_back_to_the_client(self.channel_name, message)
  16.  
  17. # And send some result back to that client immediately
  18. self.send(text_data=json.dumps({'message': 'Your request was received!'}))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement