原文連接html
趁着悠閒研究了一下websocket,並利用python和html簡單的實現了簡單的聊天系統, 但願對想要了解的有所幫助,有什麼好的意見還請你們提出。
編程語言:python,htmlpython
實現功能: 在瀏覽器開啓兩個對話窗口並進行聊天web
須要的第三方庫:編程
pip install websocketsjson
關於websocke:後端
WebSocket protocol 是HTML5一種新的協議瀏覽器
實現了瀏覽器與服務器全雙工通訊服務器
我爲何要用:websocket
實現web頁面的即時通信socket
去除輪詢帶來的諸多缺點(這個網上一搜一大把)
發信過程
# codind=utf-8 import asyncio import websockets import json import time ALLSOKETS = {} def add_connection(ws_id, ws): global ALLSOKETS ALLSOKETS[ws_id] = ws print(ALLSOKETS) def filter_handle(ws_id): return ALLSOKETS.get(ws_id) async def handler(websocket, path): # print(path) while True: . . .
http://yunsonbai.top/2016/12/18/%E5%88%A9%E7%94%A8websocket%E5%AE%9E%E7%8E%B0%E8%81%8A%E5%A4%A9%E5%B0%8F%E5%BA%94%E7%94%A8/