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 797B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # chat/consumers.py
  2. import json
  3. from channels.generic.websocket import WebsocketConsumer
  4. import wsps.tasks_loop
  5. p=print
  6. class ChatConsumer(WebsocketConsumer):
  7. def connect(self):
  8. p("!!!!!!!!!!!!!!!!!!!!")
  9. print("",end="",flush=True)
  10. self.accept()
  11. def disconnect(self, close_code):
  12. pass
  13. def receive(self, text_data):
  14. p("text_data:",text_data)
  15. print("",end="",flush=True)
  16. text_data_json = json.loads(text_data)
  17. message = text_data_json['message']
  18. self.send(text_data=json.dumps({
  19. 'message': message
  20. }))
  21. self.send(text_data=json.dumps({
  22. 'message': {"abc":123}
  23. }))
  24. # print(">>>>>>>>>>>>>")
  25. print("++?",end="\n",flush=True)
  26. # print("++",end="\n",flush=True)