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.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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(
  9. wsps.tasks_loop.AclTaskMixin,
  10. wsps.tasks_loop.AconMixin,
  11. AsyncWebsocketConsumer
  12. ):
  13. # def connect(self):
  14. async def ws_conn(self):
  15. p("!!!!!!!!!!!!!!!!!!!!?")
  16. print("",end="",flush=True)
  17. # time.sleep(1.5)
  18. # p("!!!!!!!!!!!!!!!!!!!!")
  19. # print("",end="",flush=True)
  20. self.accept()
  21. async def ws_disconn(self, close_code):
  22. pass
  23. async def ws_rec(self, text_data):
  24. p("text_data:",text_data)
  25. print("",end="",flush=True)
  26. text_data_json = json.loads(text_data)
  27. message = text_data_json['message']
  28. self.send(text_data=json.dumps({
  29. 'message': message
  30. }))
  31. self.send(text_data=json.dumps({
  32. 'zzz': {"abc":123}
  33. }))
  34. # print(">>>>>>>>>>>>>")
  35. print("++?",end="\n",flush=True)
  36. # print("++2?",end="\n",flush=True)
  37. # print("++",end="\n",flush=True)