原文连接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/