asgi + daphne
This commit is contained in:
parent
6f4282d96e
commit
9bf24b072b
7 changed files with 76 additions and 31 deletions
14
testapi/consumers.py
Normal file
14
testapi/consumers.py
Normal 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}))
|
||||
Loading…
Add table
Add a link
Reference in a new issue