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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. p("!!!!!!!!!!!!!!!!!!!!?")
  11. print("",end="",flush=True)
  12. # time.sleep(1.5)
  13. # p("!!!!!!!!!!!!!!!!!!!!")
  14. # print("",end="",flush=True)
  15. self.accept()
  16. def disconnect(self, close_code):
  17. pass
  18. def receive(self, text_data):
  19. p("text_data:",text_data)
  20. print("",end="",flush=True)
  21. text_data_json = json.loads(text_data)
  22. message = text_data_json['message']
  23. self.send(text_data=json.dumps({
  24. 'message': message
  25. }))
  26. self.send(text_data=json.dumps({
  27. 'zzz': {"abc":123}
  28. }))
  29. # print(">>>>>>>>>>>>>")
  30. print("++?",end="\n",flush=True)
  31. # print("++2?",end="\n",flush=True)
  32. # print("++",end="\n",flush=True)