AsyncWebsocketConsumerのドキュメントの下記のコードにおいて、groups=["broadcast"]の部分は何をしているのでしょうか?
この部分を削除しても問題なく動作するので、何が行われているのかがわかりません。ご教授お願いします。
python
1from channels.generic.websocket import AsyncWebsocketConsumer 2 3class MyConsumer(AsyncWebsocketConsumer): 4 groups = ["broadcast"] 5 6 async def connect(self): 7 # Called on connection. 8 # To accept the connection call: 9 await self.accept() 10 # Or accept the connection and specify a chosen subprotocol. 11 # A list of subprotocols specified by the connecting client 12 # will be available in self.scope['subprotocols'] 13 await self.accept("subprotocol") 14 # To reject the connection, call: 15 await self.close() 16 17 async def receive(self, text_data=None, bytes_data=None): 18 # Called with either text_data or bytes_data for each frame 19 # You can call: 20 await self.send(text_data="Hello world!") 21 # Or, to send a binary frame: 22 await self.send(bytes_data="Hello world!") 23 # Want to force-close the connection? Call: 24 await self.close() 25 # Or add a custom WebSocket error code! 26 await self.close(code=4123) 27 28 async def disconnect(self, close_code): 29 # Called when the socket closes
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/12/24 05:47