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 1.1KB

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