文章詳情頁
python - Django利用dwebsocket實(shí)現(xiàn)后臺數(shù)據(jù)更新實(shí)時(shí)更新到前端?
瀏覽:194日期:2022-09-01 13:50:55
問題描述
實(shí)現(xiàn)的功能是django后臺數(shù)據(jù)更新之后,例如說一個(gè)群組人員增加,不刷新頁面實(shí)現(xiàn)推送消息的功能,但是不是很懂dwebsocket的機(jī)制:
給的實(shí)例代碼中:
@accept_websocketdef 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()傳遞的是一個(gè)什么參數(shù)呢?如何從后端發(fā)送更新的消息呢?
問題解答
回答1:不是應(yīng)該前端直接定時(shí)請求的么?
相關(guān)文章:
1. javascript - sublime快鍵鍵問題2. javascript - immutable配合react提升性能?3. css - 寫頁面遇到個(gè)布局問題,求大佬們幫解答,在線等,急!~4. javascript - nodejs關(guān)于進(jìn)程間發(fā)送句柄的一點(diǎn)疑問5. Apache 已經(jīng)把網(wǎng)站根目錄的改為allow from all了,但是服務(wù)器還是不能訪問?6. 實(shí)現(xiàn)bing搜索工具urlAPI提交7. 配置Apache時(shí),添加對PHP的支持時(shí)語法錯(cuò)誤8. vue.js - Vue 如何像Angular.js watch 一樣監(jiān)聽數(shù)據(jù)變化9. javascript - 移動端上不能實(shí)現(xiàn)拖拽布局嗎?10. phpstudy8.1支持win11系統(tǒng)嗎?
排行榜

熱門標(biāo)簽
網(wǎng)公網(wǎng)安備