{"id":2863,"date":"2025-03-16T12:38:24","date_gmt":"2025-03-16T04:38:24","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=2863"},"modified":"2025-03-16T12:38:24","modified_gmt":"2025-03-16T04:38:24","slug":"python3-%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b18%ef%bc%9awebsocket-%e5%ae%89%e5%85%a8%e6%80%a7%e4%bf%9d%e9%9a%9c","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/03\/16\/python3-%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b18%ef%bc%9awebsocket-%e5%ae%89%e5%85%a8%e6%80%a7%e4%bf%9d%e9%9a%9c\/","title":{"rendered":"Python3 \u7f51\u7edc\u7f16\u7a0b18\uff1aWebSocket \u5b89\u5168\u6027\u4fdd\u969c"},"content":{"rendered":"\n<p>WebSocket \u662f\u4e00\u79cd\u53cc\u5411\u901a\u4fe1\u534f\u8bae\uff0c\u7531\u4e8e\u5176\u957f\u8fde\u63a5\u7279\u6027\uff0c\u9762\u4e34\u7740\u4e0d\u540c\u4e8e HTTP \u7684\u5b89\u5168\u6311\u6218\u3002\u4fdd\u62a4 WebSocket \u670d\u52a1\u4e0d\u53d7\u653b\u51fb\u81f3\u5173\u91cd\u8981\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u654f\u611f\u6570\u636e\u65f6\u3002\u4ee5\u4e0b\u662f\u786e\u4fdd WebSocket \u670d\u52a1\u5b89\u5168\u7684\u51e0\u4e2a\u91cd\u8981\u65b9\u9762\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>18.1 \u52a0\u5bc6\u901a\u4fe1<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>18.1.1 \u4f7f\u7528 WSS\uff08WebSocket Secure\uff09<\/strong><\/h3>\n\n\n\n<p>\u4e3a\u4e86\u9632\u6b62\u6570\u636e\u5728\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u88ab\u7a83\u53d6\u6216\u7be1\u6539\uff0cWebSocket \u901a\u4fe1\u5e94\u8be5\u901a\u8fc7\u52a0\u5bc6\u8fde\u63a5\u8fdb\u884c\u3002\u4e0e HTTPS \u76f8\u4f3c\uff0cWSS \u662f WebSocket \u7684\u52a0\u5bc6\u7248\u672c\uff0c\u5b83\u4f7f\u7528 TLS\uff08\u4f20\u8f93\u5c42\u5b89\u5168\u534f\u8bae\uff09\u8fdb\u884c\u52a0\u5bc6\u3002\u4f7f\u7528 WSS \u53ef\u4ee5\u6709\u6548\u9632\u6b62\u4e2d\u95f4\u4eba\u653b\u51fb\uff08MITM\uff09\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u542f\u7528 WSS \u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Python WebSocket \u670d\u52a1\u5668<\/strong>\uff08\u4f7f\u7528 <code>websockets<\/code> \u5e93\uff09\u542f\u7528 WSS\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>import asyncio\nimport websockets\nimport ssl\n\n# SSL Context\nssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)\nssl_context.load_cert_chain(certfile=\"server.crt\", keyfile=\"server.key\")\n\n# WebSocket Server\nasync def handler(websocket, path):\n    await websocket.send(\"Hello, secure WebSocket!\")\n\nstart_server = websockets.serve(handler, \"localhost\", 8765, ssl=ssl_context)\n\nasyncio.get_event_loop().run_until_complete(start_server)\nasyncio.get_event_loop().run_forever()<\/code><\/pre>\n\n\n\n<p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>ssl.create_default_context()<\/code> \u7528\u4e8e\u52a0\u8f7d\u8bc1\u4e66\u5e76\u521b\u5efa\u5b89\u5168\u7684 SSL\/TLS \u8fde\u63a5\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>18.1.2 \u5f3a\u5236 HTTPS\/WSS<\/strong><\/h3>\n\n\n\n<p>\u5982\u679c WebSocket \u8fde\u63a5\u662f\u901a\u8fc7\u6d4f\u89c8\u5668\u53d1\u8d77\u7684\uff0c\u5efa\u8bae\u5f3a\u5236\u5ba2\u6237\u7aef\u53ea\u80fd\u4f7f\u7528 HTTPS\/WSS \u534f\u8bae\uff0c\u800c\u4e0d\u662f HTTP\/WS\u3002\u8bb8\u591a\u73b0\u4ee3\u6d4f\u89c8\u5668\u4f1a\u5c06 HTTP \u534f\u8bae\u89c6\u4e3a\u4e0d\u5b89\u5168\uff0c\u5c24\u5176\u662f\u5728\u901a\u8fc7 HTTP \u8bf7\u6c42\u654f\u611f\u6570\u636e\u65f6\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>18.2 \u8eab\u4efd\u9a8c\u8bc1\u4e0e\u6388\u6743<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>18.2.1 Token \u8ba4\u8bc1<\/strong><\/h3>\n\n\n\n<p>\u4e3a\u4e86\u4fdd\u62a4 WebSocket \u670d\u52a1\uff0c\u5fc5\u987b\u786e\u4fdd\u6bcf\u4e2a\u8fde\u63a5\u7684\u5ba2\u6237\u7aef\u662f\u5408\u6cd5\u7684\u3002\u8fd9\u901a\u5e38\u901a\u8fc7\u8eab\u4efd\u9a8c\u8bc1\u4ee4\u724c\uff08Token\uff09\u6765\u5b9e\u73b0\u3002\u5728\u6bcf\u4e2a WebSocket \u8fde\u63a5\u5efa\u7acb\u65f6\uff0c\u53ef\u4ee5\u8981\u6c42\u5ba2\u6237\u7aef\u63d0\u4f9b\u4e00\u4e2a\u8eab\u4efd\u9a8c\u8bc1 Token\uff08\u5982 JWT\uff09\uff0c\u4ee5\u9a8c\u8bc1\u5176\u5408\u6cd5\u6027\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>JWT \u8ba4\u8bc1\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>WebSocket \u670d\u52a1\u5668\uff08Python \u7aef\uff09<\/strong>\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>import websockets\nimport asyncio\nimport jwt\nfrom websockets.exceptions import InvalidState\n\n# \u9a8c\u8bc1 Token\ndef verify_token(token):\n    try:\n        # \u89e3\u7801\u5e76\u9a8c\u8bc1 JWT\n        decoded = jwt.decode(token, \"secret\", algorithms=&#91;\"HS256\"])\n        return decoded\n    except jwt.InvalidTokenError:\n        raise InvalidState(\"Invalid Token\")\n\n# WebSocket \u5904\u7406\u51fd\u6570\nasync def handler(websocket, path):\n    token = websocket.request_headers.get('Authorization')\n    if token:\n        try:\n            # \u53bb\u9664 \"Bearer \" \u90e8\u5206\n            token = token.replace('Bearer ', '')\n            decoded_data = verify_token(token)\n            await websocket.send(f\"Hello {decoded_data&#91;'username']}!\")\n        except InvalidState:\n            await websocket.send(\"Invalid Token!\")\n            await websocket.close()\n    else:\n        await websocket.send(\"Authorization header missing!\")\n        await websocket.close()\n\n# \u542f\u52a8 WebSocket \u670d\u52a1\nstart_server = websockets.serve(handler, \"localhost\", 8765)\n\nasyncio.get_event_loop().run_until_complete(start_server)\nasyncio.get_event_loop().run_forever()<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728\u5ba2\u6237\u7aef\u8fde\u63a5\u65f6\uff0c\u9700\u8981\u53d1\u9001\u6b63\u786e\u7684 Token\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>const socket = new WebSocket('wss:\/\/localhost:8765', {\n  headers: {\n    Authorization: 'Bearer &lt;your-jwt-token&gt;'\n  }\n});<\/code><\/pre>\n\n\n\n<p>\u8fd9\u6837\uff0c\u670d\u52a1\u7aef\u53ef\u4ee5\u9a8c\u8bc1\u6bcf\u4e2a\u8fde\u63a5\u8bf7\u6c42\uff0c\u786e\u4fdd\u53ea\u6709\u901a\u8fc7\u8eab\u4efd\u9a8c\u8bc1\u7684\u5ba2\u6237\u7aef\u624d\u80fd\u8fde\u63a5\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>18.2.2 \u5ba2\u6237\u7aef\u8ba4\u8bc1<\/strong><\/h3>\n\n\n\n<p>\u5ba2\u6237\u7aef\u8ba4\u8bc1\u4e0d\u4ec5\u9650\u4e8e\u901a\u8fc7 Token\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u5176\u4ed6\u65b9\u5f0f\u8fdb\u884c\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u7528\u6237\u540d\u548c\u5bc6\u7801\u9a8c\u8bc1\uff0c\u6216\u8005\u57fa\u4e8e OAuth \u7684\u6388\u6743\u65b9\u5f0f\u3002\u5728\u654f\u611f\u4fe1\u606f\u7684\u4f20\u8f93\u4e2d\uff0c\u786e\u4fdd\u8eab\u4efd\u9a8c\u8bc1\u662f\u4fdd\u62a4\u6570\u636e\u9690\u79c1\u7684\u5173\u952e\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>18.3 \u9632\u6b62 DoS \u548c DDoS \u653b\u51fb<\/strong><\/h2>\n\n\n\n<p>WebSocket \u7684\u957f\u8fde\u63a5\u7279\u6027\u610f\u5473\u7740\u5b83\u5bb9\u6613\u53d7\u5230 <strong>\u62d2\u7edd\u670d\u52a1\uff08DoS\uff09<\/strong> \u6216 <strong>\u5206\u5e03\u5f0f\u62d2\u7edd\u670d\u52a1\uff08DDoS\uff09<\/strong> \u653b\u51fb\u3002\u653b\u51fb\u8005\u53ef\u80fd\u901a\u8fc7\u5efa\u7acb\u5927\u91cf\u7684 WebSocket \u8fde\u63a5\uff0c\u5bfc\u81f4\u670d\u52a1\u7aef\u8d44\u6e90\u8017\u5c3d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>18.3.1 \u9650\u5236\u8fde\u63a5\u6570<\/strong><\/h3>\n\n\n\n<p>\u53ef\u4ee5\u9650\u5236\u6bcf\u4e2a\u5ba2\u6237\u7aef\u6216\u6bcf\u4e2a IP \u5730\u5740\u7684\u6700\u5927\u8fde\u63a5\u6570\uff0c\u907f\u514d\u653b\u51fb\u8005\u901a\u8fc7\u521b\u5efa\u5927\u91cf\u8fde\u63a5\u6765\u6d88\u8017\u670d\u52a1\u5668\u8d44\u6e90\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u9650\u5236\u8fde\u63a5\u6570\u793a\u4f8b\uff1a<\/strong><\/h4>\n\n\n\n<p>\u5728 WebSocket \u670d\u52a1\u5668\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bb0\u5f55\u6bcf\u4e2a\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u6570\u91cf\uff0c\u6765\u9650\u5236\u6bcf\u4e2a IP \u7684\u6700\u5927\u8fde\u63a5\u6570\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>18.3.2 \u9632\u706b\u5899\u4e0e\u53cd\u5411\u4ee3\u7406<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528 <strong>\u53cd\u5411\u4ee3\u7406<\/strong>\uff08\u5982 Nginx \u6216 HAProxy\uff09\u6765\u5904\u7406 WebSocket \u6d41\u91cf\uff0c\u53ef\u4ee5\u6709\u6548\u9694\u79bb\u5916\u90e8\u653b\u51fb\uff0c\u5e76\u901a\u8fc7\u8bbe\u7f6e\u9650\u901f\u3001\u9ed1\u540d\u5355\u7b49\u7b56\u7565\u589e\u5f3a\u5b89\u5168\u6027\u3002<\/li>\n\n\n\n<li>\u914d\u7f6e <strong>\u9632\u706b\u5899<\/strong>\uff0c\u53ea\u5141\u8bb8\u5408\u6cd5\u7684 IP \u5730\u5740\u8bbf\u95ee WebSocket \u670d\u52a1\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>18.4 \u9632\u6b62\u8de8\u7ad9\u811a\u672c\u653b\u51fb\uff08XSS\uff09<\/strong><\/h2>\n\n\n\n<p>WebSocket \u5728\u6570\u636e\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u672c\u8eab\u5e76\u4e0d\u4f1a\u76f4\u63a5\u5bfc\u81f4 XSS \u653b\u51fb\uff0c\u4f46\u5b83\u53ef\u80fd\u88ab\u6076\u610f\u811a\u672c\u5229\u7528\u6765\u8fdb\u884c\u653b\u51fb\u3002\u4e3a\u4e86\u907f\u514d XSS \u653b\u51fb\uff0c\u53ef\u4ee5\u5728 WebSocket \u670d\u52a1\u7aef\u548c\u5ba2\u6237\u7aef\u90fd\u8fdb\u884c\u6570\u636e\u9a8c\u8bc1\u548c\u6e05\u7406\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>18.4.1 \u8f93\u5165\u9a8c\u8bc1\u4e0e\u6e05\u7406<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u670d\u52a1\u7aef<\/strong>\uff1a\u9a8c\u8bc1\u6240\u6709\u4ece\u5ba2\u6237\u7aef\u63a5\u6536\u5230\u7684\u6570\u636e\uff0c\u907f\u514d\u6267\u884c\u4efb\u4f55\u6076\u610f\u811a\u672c\u3002\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u5e93\uff08\u5982 Python \u7684 <code>html<\/code> \u6a21\u5757\uff09\u5bf9\u4f20\u5165\u6570\u636e\u8fdb\u884c\u8f6c\u4e49\u3002<\/li>\n\n\n\n<li><strong>\u5ba2\u6237\u7aef<\/strong>\uff1a\u786e\u4fdd\u4f20\u5165\u7684\u6570\u636e\u8fdb\u884c\u9002\u5f53\u7684\u9a8c\u8bc1\u548c\u6e05\u7406\uff0c\u907f\u514d\u672a\u9a8c\u8bc1\u7684\u811a\u672c\u5728\u5ba2\u6237\u7aef\u6267\u884c\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>18.4.2 Content Security Policy\uff08CSP\uff09<\/strong><\/h3>\n\n\n\n<p>\u901a\u8fc7\u8bbe\u7f6e CSP\uff0c\u907f\u514d WebSocket \u6570\u636e\u4f20\u8f93\u4e2d\u7684\u6076\u610f\u811a\u672c\u6ce8\u5165\u3002CSP \u53ef\u4ee5\u9650\u5236\u9875\u9762\u52a0\u8f7d\u7684\u8d44\u6e90\u6765\u6e90\uff0c\u9632\u6b62\u6f5c\u5728\u7684\u6076\u610f\u811a\u672c\u52a0\u8f7d\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>18.5 \u6570\u636e\u5b8c\u6574\u6027\u4fdd\u62a4<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>18.5.1 \u6821\u9a8c\u548c\u4e0e\u6d88\u606f\u7b7e\u540d<\/strong><\/h3>\n\n\n\n<p>\u4e3a\u4e86\u786e\u4fdd WebSocket \u6d88\u606f\u5728\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u4e0d\u88ab\u7be1\u6539\uff0c\u53ef\u4ee5\u4f7f\u7528\u54c8\u5e0c\u6821\u9a8c\u6216\u6d88\u606f\u7b7e\u540d\u6765\u4fdd\u62a4\u6570\u636e\u5b8c\u6574\u6027\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728\u670d\u52a1\u7aef\u548c\u5ba2\u6237\u7aef\u4e4b\u95f4\u5efa\u7acb\u5bc6\u94a5\u5e76\u7b7e\u540d\u6bcf\u6761\u6d88\u606f\u3002\u63a5\u6536\u65b9\u901a\u8fc7\u9a8c\u8bc1\u7b7e\u540d\u6765\u68c0\u67e5\u6570\u636e\u662f\u5426\u88ab\u7be1\u6539\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>18.6 \u9632\u6b62\u8de8\u7ad9\u8bf7\u6c42\u4f2a\u9020\uff08CSRF\uff09<\/strong><\/h2>\n\n\n\n<p>\u867d\u7136 WebSocket \u672c\u8eab\u4e0d\u6613\u53d7\u5230\u4f20\u7edf\u7684 CSRF \u653b\u51fb\uff08\u7531\u4e8e\u5b83\u4e0d\u4f9d\u8d56\u4e8e\u6d4f\u89c8\u5668\u7684 cookies\uff09\uff0c\u4f46\u5b83\u53ef\u80fd\u901a\u8fc7\u5176\u4ed6\u653b\u51fb\u6e20\u9053\u53d7\u5230\u5229\u7528\u3002\u53ef\u4ee5\u901a\u8fc7\u91c7\u7528 JWT \u7b49\u5b89\u5168\u63aa\u65bd\u6765\u9632\u6b62 CSRF \u653b\u51fb\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>18.7 \u5b89\u5168 WebSocket \u793a\u4f8b<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u524d\u7aef<\/strong>\uff08JavaScript\uff09\uff1a \u5728\u5ba2\u6237\u7aef\u8fde\u63a5\u65f6\uff0c\u4f7f\u7528\u52a0\u5bc6\u8fde\u63a5 <code>wss<\/code> \u548c\u5e26\u6709\u9a8c\u8bc1\u7684\u8bf7\u6c42\u5934\uff0c\u786e\u4fdd\u6570\u636e\u4f20\u8f93\u5b89\u5168\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>const socket = new WebSocket('wss:\/\/example.com\/socket', {\n  headers: {\n    Authorization: 'Bearer &lt;jwt-token&gt;'\n  }\n});\n\nsocket.onmessage = (event) =&gt; {\n  console.log('Message from server: ', event.data);\n};\n\nsocket.onerror = (error) =&gt; {\n  console.error('WebSocket Error: ', error);\n};<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u540e\u7aef<\/strong>\uff08Python\uff09\uff1a \u4f7f\u7528 <code>websockets<\/code> \u5e93\u5904\u7406 WebSocket \u8fde\u63a5\uff0c\u5e76\u9a8c\u8bc1\u8eab\u4efd Token\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>import websockets\nimport asyncio\nimport jwt\n\nasync def handler(websocket, path):\n    token = websocket.request_headers.get('Authorization')\n    if token:\n        token = token.replace('Bearer ', '')\n        try:\n            decoded = jwt.decode(token, 'secret', algorithms=&#91;'HS256'])\n            await websocket.send(f\"Hello {decoded&#91;'username']}!\")\n        except jwt.ExpiredSignatureError:\n            await websocket.send(\"Token expired!\")\n            await websocket.close()\n        except jwt.InvalidTokenError:\n            await websocket.send(\"Invalid token!\")\n            await websocket.close()\n\nstart_server = websockets.serve(handler, 'localhost', 8765)\n\nasyncio.get_event_loop().run_until_complete(start_server)\nasyncio.get_event_loop().run_forever()<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>\u603b\u7ed3\uff1a<\/strong><\/p>\n\n\n\n<p>WebSocket \u7684\u5b89\u5168\u6027\u662f\u591a\u65b9\u9762\u7684\uff0c\u6d89\u53ca\u6570\u636e\u52a0\u5bc6\u3001\u8eab\u4efd\u9a8c\u8bc1\u3001\u8fde\u63a5\u63a7\u5236\u3001\u9632\u6b62 DoS \u653b\u51fb\u3001\u6570\u636e\u5b8c\u6574\u6027\u4fdd\u62a4\u7b49\u3002\u901a\u8fc7\u52a0\u5bc6\u901a\u4fe1\uff08WSS\uff09\u3001Token \u8ba4\u8bc1\u3001\u53cd\u5411\u4ee3\u7406\u548c\u9632\u706b\u5899\u7b56\u7565\u7b49\uff0c\u53ef\u4ee5\u6709\u6548\u4fdd\u62a4 WebSocket \u670d\u52a1\u514d\u53d7\u653b\u51fb\uff0c\u786e\u4fdd\u6570\u636e\u5b89\u5168\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>\u4e0b\u7bc7\u6587\u7ae0\u6211\u4eec\u4e86\u89e3 WebSocket \u7684\u9519\u8bef\u5904\u7406\u4e0e\u6062\u590d\u673a\u5236\uff01<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>WebSocket \u662f\u4e00\u79cd\u53cc\u5411\u901a\u4fe1\u534f\u8bae\uff0c\u7531\u4e8e\u5176\u957f\u8fde\u63a5\u7279\u6027\uff0c\u9762\u4e34\u7740\u4e0d\u540c\u4e8e HTTP \u7684\u5b89\u5168\u6311\u6218\u3002\u4fdd\u62a4 WebSo [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79],"tags":[],"class_list":["post-2863","post","type-post","status-publish","format-standard","hentry","category-python-3-"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2863","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=2863"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2863\/revisions"}],"predecessor-version":[{"id":2865,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2863\/revisions\/2865"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=2863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=2863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=2863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}