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.
22 lines
609 B
22 lines
609 B
10 months ago
|
from channels.generic.websocket import WebsocketConsumer
|
||
|
import json
|
||
|
|
||
|
|
||
|
class UpdateConsumer(WebsocketConsumer):
|
||
|
def connect(self):
|
||
|
self.accept()
|
||
|
self.send('你已经连接成功')
|
||
|
|
||
|
def receive(self, text_data=None, bytes_data=None):
|
||
|
if text_data is None:
|
||
|
self.send('你发了啥')
|
||
|
if text_data == 'update':
|
||
|
self.send(json.dumps({'code': '111'}))
|
||
|
if text_data == 'close':
|
||
|
self.send('白白')
|
||
|
self.close()
|
||
|
self.disconnect('500')
|
||
|
else:
|
||
|
self.send(f'你收到的消息是{text_data}')
|
||
|
|