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

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