asgi + daphne

This commit is contained in:
aa.afanasyev 2025-07-15 01:34:22 +09:00
parent 6f4282d96e
commit 9bf24b072b
7 changed files with 76 additions and 31 deletions

14
testapi/consumers.py Normal file
View file

@ -0,0 +1,14 @@
from channels.generic.websocket import AsyncWebsocketConsumer
import json
class EchoConsumer(AsyncWebsocketConsumer):
async def connect(self):
await self.accept()
await self.send(text_data=json.dumps({"message": "WebSocket connected!"}))
async def disconnect(self, close_code):
pass
async def receive(self, text_data):
await self.send(text_data=json.dumps({"echo": text_data}))