You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

consumers.py 551B

12345678910111213141516171819202122232425
  1. # chat/consumers.py
  2. import json
  3. from channels.generic.websocket import WebsocketConsumer
  4. import wsps.tasks_loop
  5. class ChatConsumer(WebsocketConsumer):
  6. def connect(self):
  7. self.accept()
  8. def disconnect(self, close_code):
  9. pass
  10. def receive(self, text_data):
  11. text_data_json = json.loads(text_data)
  12. message = text_data_json['message']
  13. self.send(text_data=json.dumps({
  14. 'message': message
  15. }))
  16. self.send(text_data=json.dumps({
  17. 'message': {"abc":123}
  18. }))