python - Django利用dwebsocket实现后台数据更新实时更新到前端?
PHP中文网
PHP中文网 2017-04-18 10:25:12
0
1
1117

实现的功能是django后台数据更新之后,例如说一个群组人员增加,不刷新页面实现推送消息的功能,但是不是很懂dwebsocket的机制:

给的实例代码中:

@accept_websocket
def echo(request):
    if request.is_websocket:
        lock = threading.RLock()
        try:
            lock.acquire()
            clients.append(request.websocket)
            for message in request.websocket:
                if not message:
                    break
              
                for client in clients:
                    client.send(message)
        finally:
            clients.remove(request.websocket)
            lock.release()

client.send()传递的是一个什么参数呢?
如何从后端发送更新的消息呢?

PHP中文网
PHP中文网

认证0级讲师

reply all(1)
Peter_Zhu

Shouldn’t the front-end directly request it regularly?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template