{"id":17313,"date":"2025-04-18T23:46:58","date_gmt":"2025-04-18T15:46:58","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/17313.html"},"modified":"2025-04-18T23:46:58","modified_gmt":"2025-04-18T15:46:58","slug":"websocket%e5%8d%8f%e8%ae%ae%e9%87%8c%e5%ae%a2%e6%88%b7%e7%ab%af%e5%8f%91%e9%80%81%e7%bb%99%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%9a%84%e6%95%b0%e6%8d%ae%e4%bc%9a%e7%94%a84%e5%ad%97%e8%8a%82%e7%9a%84%e6%8e%a9","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/17313.html","title":{"rendered":"WebSocket\u534f\u8bae\u91cc\u5ba2\u6237\u7aef\u53d1\u9001\u7ed9\u670d\u52a1\u5668\u7684\u6570\u636e\u4f1a\u75284\u5b57\u8282\u7684\u63a9\u7801\u5faa\u73af\u5f02\u6216\u7684\u5206\u6790"},"content":{"rendered":"<p>\u9996\u5148&#xff0c;\u6211\u9700\u8981\u56de\u987eWebSocket\u534f\u8bae\u4e2d\u5bf9\u63a9\u7801\u5904\u7406\u7684\u5177\u4f53\u8981\u6c42\u3002\u6839\u636eRFC 6455&#xff0c;\u5ba2\u6237\u7aef\u53d1\u9001\u5230\u670d\u52a1\u5668\u7684\u5e27\u5fc5\u987b\u4f7f\u7528\u63a9\u7801&#xff0c;\u800c\u670d\u52a1\u5668\u53d1\u9001\u7684\u5e27\u4e0d\u9700\u8981\u63a9\u7801\u3002\u63a9\u7801\u662f4\u5b57\u8282\u7684&#xff0c;\u5e94\u7528\u4e8e\u6709\u6548\u8f7d\u8377\u6570\u636e&#xff0c;\u6bcf\u4e2a\u5b57\u8282\u4f9d\u6b21\u4e0e\u63a9\u7801\u7684\u5bf9\u5e94\u5b57\u8282\u5f02\u6216&#xff0c;\u5faa\u73af\u4f7f\u7528\u63a9\u7801\u3002\u4f8b\u5982&#xff0c;\u7b2c\u4e00\u4e2a\u5b57\u8282\u4e0e\u63a9\u7801\u7684\u7b2c0\u4e2a\u5b57\u8282\u5f02\u6216&#xff0c;\u7b2c\u4e8c\u4e2a\u4e0e\u7b2c1\u4e2a&#xff0c;\u7b2c\u4e09\u4e2a\u4e0e\u7b2c2\u4e2a&#xff0c;\u7b2c\u56db\u4e2a\u4e0e\u7b2c3\u4e2a&#xff0c;\u7b2c\u4e94\u4e2a\u53c8\u56de\u5230\u7b2c0\u4e2a&#xff0c;\u4f9d\u6b64\u7c7b\u63a8\u3002<\/p>\n<p>\u7528\u6237\u63d0\u4f9b\u7684unmask\u51fd\u6570\u770b\u8d77\u6765\u662f\u6b63\u786e\u7684&#xff0c;\u56e0\u4e3a\u5b83\u786e\u5b9e\u5faa\u73af\u4f7f\u7528maskBytes\u6570\u7ec4\u4e2d\u7684\u56db\u4e2a\u5b57\u8282&#xff0c;\u5bf9data\u7684\u6bcf\u4e2a\u5b57\u8282\u8fdb\u884c\u5f02\u6216\u64cd\u4f5c\u3002\u6d4b\u8bd5\u7528\u4f8b\u8986\u76d6\u4e86\u7a7a\u6570\u636e\u3001\u6570\u636e\u957f\u5ea6\u5c0f\u4e8e4\u3001\u8d85\u8fc74\u3001\u5168\u96f6\u63a9\u7801\u3001\u5168FF\u63a9\u7801\u4ee5\u53ca\u4e00\u4e2a\u5b9e\u9645\u6848\u4f8b&#xff08;\u751f\u6210&#034;Hello&#034;&#xff09;\u3002\u8fd9\u4e9b\u90fd\u662f\u5408\u7406\u7684\u6d4b\u8bd5\u70b9\u3002<\/p>\n<p>\u63a5\u4e0b\u6765&#xff0c;\u6211\u9700\u8981\u8003\u8651\u662f\u5426\u6709\u5176\u4ed6\u8fb9\u754c\u60c5\u51b5\u6216\u5f02\u5e38\u60c5\u51b5\u672a\u88ab\u8986\u76d6\u3002\u4f8b\u5982&#xff1a;<\/p>\n<li>\n<p>\u63a9\u7801\u6570\u7ec4\u957f\u5ea6\u4e0d\u7b49\u4e8e4\u7684\u60c5\u51b5&#xff1a;\u6839\u636eWebSocket\u534f\u8bae&#xff0c;\u63a9\u7801\u5fc5\u987b\u662f4\u5b57\u8282&#xff0c;\u4f46\u51fd\u6570\u662f\u5426\u5bf9\u6b64\u505a\u4e86\u5904\u7406&#xff1f;\u5f53\u524d\u7684\u51fd\u6570\u5047\u8bbemaskBytes\u662f4\u5b57\u8282&#xff0c;\u5982\u679c\u4f20\u5165\u7684maskBytes\u957f\u5ea6\u4e0d\u7b49\u4e8e4&#xff0c;\u53ef\u80fd\u4f1a\u5bfc\u81f4\u9519\u8bef\u3002\u4f8b\u5982&#xff0c;\u5982\u679cmaskBytes\u957f\u5ea6\u4e3a3&#xff0c;i%4\u7684\u7ed3\u679c\u4f1a\u662f0\u30011\u30012\u30010\u30011\u30012&#xff0c;\u8fd9\u6837\u4f1a\u8bbf\u95eemaskBytes[3]&#xff0c;\u5bfc\u81f4\u8d8a\u754c\u3002\u4f46\u6839\u636e\u534f\u8bae&#xff0c;\u8fd9\u79cd\u60c5\u51b5\u4e0d\u5e94\u8be5\u53d1\u751f&#xff0c;\u56e0\u4e3a\u5ba2\u6237\u7aef\u5fc5\u987b\u53d1\u90014\u5b57\u8282\u7684\u63a9\u7801\u3002\u4f46\u51fd\u6570\u672c\u8eab\u662f\u5426\u5e94\u8be5\u6dfb\u52a0\u9632\u5fa1\u6027\u4ee3\u7801&#xff1f;\u7528\u6237\u53ef\u80fd\u5e0c\u671b\u51fd\u6570\u5728\u975e\u6cd5\u8f93\u5165\u65f6\u5982\u4f55\u5904\u7406&#xff1f;\u662f\u5426\u9700\u8981\u6d4b\u8bd5\u8fd9\u79cd\u60c5\u51b5&#xff1f;<\/p>\n<\/li>\n<li>\n<p>\u975eBuffer\u7c7b\u578b\u7684data\u8f93\u5165&#xff1a;\u51fd\u6570\u662f\u5426\u5047\u8bbedata\u662fBuffer\u7c7b\u578b&#xff1f;\u5982\u679c\u4f20\u5165\u7684\u662f\u5176\u4ed6\u7c7b\u578b&#xff08;\u5982Array\u3001Uint8Array\u6216\u5b57\u7b26\u4e32&#xff09;&#xff0c;\u53ef\u80fd\u4f1a\u5bfc\u81f4\u9519\u8bef\u3002\u4f46\u6839\u636e\u4e0a\u4e0b\u6587&#xff0c;\u8fd9\u4e2a\u51fd\u6570\u53ef\u80fd\u662f\u5728WebSocket\u670d\u52a1\u5668\u5185\u90e8\u4f7f\u7528&#xff0c;\u786e\u4fdddata\u662fBuffer&#xff0c;\u56e0\u6b64\u53ef\u80fd\u4e0d\u9700\u8981\u5904\u7406\u5176\u4ed6\u7c7b\u578b\u3002\u4f46\u6d4b\u8bd5\u4e2d\u5e94\u786e\u4fdd\u4f20\u5165\u7684\u662fBuffer\u3002<\/p>\n<\/li>\n<li>\n<p>\u6027\u80fd\u6d4b\u8bd5&#xff1a;\u5bf9\u4e8e\u5927\u6570\u636e\u91cf\u7684\u5904\u7406&#xff0c;\u662f\u5426\u6709\u6548\u7387\u95ee\u9898&#xff1f;\u4e0d\u8fc7\u5355\u5143\u6d4b\u8bd5\u901a\u5e38\u4e0d\u6d89\u53ca\u6027\u80fd\u6d4b\u8bd5&#xff0c;\u9664\u975e\u7279\u522b\u8981\u6c42\u3002<\/p>\n<\/li>\n<li>\n<p>\u5b57\u8282\u987a\u5e8f\u95ee\u9898&#xff1a;\u662f\u5426\u6709\u53ef\u80fd\u5728\u63a9\u7801\u7684\u5e94\u7528\u987a\u5e8f\u4e0a\u51fa\u9519&#xff1f;\u4f8b\u5982&#xff0c;\u662f\u5426\u5e94\u8be5\u6309\u5927\u7aef\u5e8f\u6216\u5c0f\u7aef\u5e8f\u5904\u7406&#xff1f;\u6839\u636eRFC&#xff0c;\u63a9\u7801\u662f\u6309\u987a\u5e8f\u4f9d\u6b21\u5faa\u73af\u5e94\u7528&#xff0c;\u6240\u4ee5\u51fd\u6570\u4e2d\u7684i%4\u662f\u6b63\u786e\u7684\u3002<\/p>\n<\/li>\n<p>\u73b0\u5728&#xff0c;\u56de\u5230\u7528\u6237\u7684\u95ee\u9898&#xff0c;\u4ed6\u4eec\u53ef\u80fd\u5e0c\u671b\u786e\u8ba4\u73b0\u6709\u7684\u6d4b\u8bd5\u662f\u5426\u8db3\u591f&#xff0c;\u6216\u8005\u662f\u5426\u6709\u5176\u4ed6\u9700\u8981\u6ce8\u610f\u7684\u5730\u65b9\u3002\u6839\u636e\u4e0a\u8ff0\u5206\u6790&#xff0c;\u73b0\u6709\u7684\u6d4b\u8bd5\u5df2\u7ecf\u8986\u76d6\u4e86\u4e3b\u8981\u60c5\u51b5&#xff0c;\u4f46\u53ef\u80fd\u9700\u8981\u8865\u5145\u5bf9\u63a9\u7801\u957f\u5ea6\u4e0d\u7b49\u4e8e4\u7684\u6d4b\u8bd5&#xff0c;\u5c3d\u7ba1\u6839\u636e\u534f\u8bae&#xff0c;\u8fd9\u79cd\u60c5\u51b5\u4e0d\u5e94\u51fa\u73b0\u3002\u4f46\u4e3a\u4e86\u4ee3\u7801\u7684\u5065\u58ee\u6027&#xff0c;\u53ef\u80fd\u9700\u8981\u6dfb\u52a0\u9519\u8bef\u5904\u7406&#xff0c;\u6bd4\u5982\u629b\u51fa\u5f02\u5e38&#xff0c;\u5426\u5219\u5f53maskBytes\u957f\u5ea6\u4e0d\u662f4\u65f6&#xff0c;\u51fd\u6570\u4f1a\u51fa\u9519\u3002\u4f8b\u5982&#xff0c;\u5f53maskBytes\u957f\u5ea6\u662f3&#xff0c;i%4\u53ef\u80fd\u4e3a3&#xff0c;\u6b64\u65f6maskBytes[3]\u4e0d\u5b58\u5728&#xff0c;\u5bfc\u81f4\u9519\u8bef\u3002<\/p>\n<p>\u4f46\u6839\u636eWebSocket\u534f\u8bae&#xff0c;\u670d\u52a1\u5668\u5728\u63a5\u6536\u5230\u5ba2\u6237\u7aef\u6d88\u606f\u65f6&#xff0c;\u63a9\u7801\u5fc5\u987b\u662f4\u5b57\u8282&#xff0c;\u56e0\u6b64\u5728\u6b63\u786e\u7684\u5b9e\u73b0\u4e2d&#xff0c;\u8c03\u7528unmask\u51fd\u6570\u4e4b\u524d&#xff0c;\u5e94\u8be5\u5df2\u7ecf\u9a8c\u8bc1\u4e86maskBytes\u7684\u957f\u5ea6\u4e3a4\u3002\u6240\u4ee5&#xff0c;\u5728\u51fd\u6570\u5185\u90e8\u53ef\u80fd\u4e0d\u9700\u8981\u5904\u7406\u8fd9\u79cd\u60c5\u51b5&#xff0c;\u800c\u662f\u7531\u4e0a\u5c42\u8c03\u7528\u8005\u4fdd\u8bc1\u3002\u56e0\u6b64&#xff0c;\u6d4b\u8bd5\u7528\u4f8b\u4e2d\u53ef\u80fd\u4e0d\u9700\u8981\u6db5\u76d6\u8fd9\u79cd\u60c5\u51b5&#xff0c;\u6216\u8005\u53ef\u4ee5\u6dfb\u52a0\u4e00\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u6765\u9a8c\u8bc1\u5f53maskBytes\u957f\u5ea6\u4e0d\u4e3a4\u65f6\u7684\u884c\u4e3a&#xff0c;\u6bd4\u5982\u662f\u5426\u629b\u51fa\u9519\u8bef\u3002<\/p>\n<p>\u4f46\u539f\u51fd\u6570\u5e76\u6ca1\u6709\u5904\u7406\u8fd9\u79cd\u60c5\u51b5&#xff0c;\u56e0\u6b64\u5728maskBytes\u957f\u5ea6\u4e0d\u8db34\u65f6&#xff0c;\u4f1a\u629b\u51fa\u9519\u8bef\u3002\u4f8b\u5982&#xff0c;\u5f53maskBytes\u662f\u7a7a\u6570\u7ec4\u65f6&#xff0c;\u8bbf\u95eemaskBytes[i%4]\u4f1a\u8d8a\u754c\u3002\u56e0\u6b64&#xff0c;\u53ef\u80fd\u9700\u8981\u5728\u4e0a\u5c42\u8c03\u7528\u65f6\u786e\u4fddmaskBytes\u7684\u957f\u5ea6\u6b63\u786e&#xff0c;\u800c\u4e0d\u662f\u5728unmask\u51fd\u6570\u5185\u90e8\u5904\u7406\u3002\u56e0\u6b64&#xff0c;\u6d4b\u8bd5\u7528\u4f8b\u662f\u5426\u5e94\u8be5\u5305\u62ec\u8fd9\u79cd\u60c5\u51b5&#xff1f;\u53ef\u80fd\u5e94\u8be5&#xff0c;\u4f46\u6839\u636e\u73b0\u6709\u7684\u6d4b\u8bd5\u7528\u4f8b&#xff0c;\u7528\u6237\u53ef\u80fd\u66f4\u5173\u6ce8\u6b63\u786e\u8def\u5f84&#xff0c;\u800c\u5f02\u5e38\u5904\u7406\u53ef\u80fd\u7531\u5176\u4ed6\u90e8\u5206\u4fdd\u8bc1\u3002<\/p>\n<p>\u53e6\u5916&#xff0c;\u8003\u8651\u5230JavaScript\u7684\u7075\u6d3b\u6027&#xff0c;\u5982\u679cmaskBytes\u7684\u5143\u7d20\u4e0d\u662f\u6574\u6570&#xff08;\u6bd4\u5982\u662f\u5b57\u7b26\u4e32\u6216\u5176\u4ed6\u7c7b\u578b&#xff09;&#xff0c;\u5f02\u6216\u64cd\u4f5c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u610f\u5916\u7ed3\u679c\u3002\u4f8b\u5982&#xff0c;\u5982\u679cmaskBytes\u4e2d\u7684\u67d0\u4e2a\u5143\u7d20\u662f\u5b57\u7b26\u4e32&#034;1&#034;&#xff0c;\u90a3\u4e48\u5728\u8fdb\u884c\u5f02\u6216\u65f6&#xff0c;\u4f1a\u8f6c\u6362\u4e3aNaN&#xff0c;\u5bfc\u81f4\u7ed3\u679c\u9519\u8bef\u3002\u4f46\u5728WebSocket\u534f\u8bae\u7684\u4e0a\u4e0b\u6587\u4e2d&#xff0c;maskBytes\u5e94\u8be5\u662f4\u4e2a\u5b57\u8282\u7684\u6570\u7ec4&#xff0c;\u6bcf\u4e2a\u5143\u7d20\u662f0-255\u7684\u6574\u6570&#xff0c;\u56e0\u6b64\u8fd9\u79cd\u60c5\u51b5\u5e94\u7531\u4e0a\u5c42\u8f93\u5165\u9a8c\u8bc1\u5904\u7406&#xff0c;\u800c\u4e0d\u662f\u5728unmask\u51fd\u6570\u4e2d\u5904\u7406\u3002\u56e0\u6b64&#xff0c;\u6d4b\u8bd5\u7528\u4f8b\u53ef\u80fd\u4e0d\u9700\u8981\u8003\u8651\u8fd9\u4e9b&#xff0c;\u9664\u975e\u60f3\u8981\u589e\u52a0\u9c81\u68d2\u6027\u6d4b\u8bd5\u3002<\/p>\n<p>\u603b\u7ed3&#xff0c;\u73b0\u6709\u7684\u6d4b\u8bd5\u7528\u4f8b\u5df2\u7ecf\u8986\u76d6\u4e86\u4e3b\u8981\u60c5\u51b5&#xff0c;\u4f46\u53ef\u80fd\u9700\u8981\u8865\u5145&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6d4b\u8bd5\u5f53maskBytes\u957f\u5ea6\u4e0d\u4e3a4\u65f6\u7684\u884c\u4e3a&#xff0c;\u786e\u4fdd\u51fd\u6570\u629b\u51fa\u9519\u8bef\u6216\u6b63\u786e\u5904\u7406&#xff08;\u4f46\u6839\u636e\u534f\u8bae&#xff0c;\u8fd9\u4e0d\u5e94\u8be5\u53d1\u751f&#xff0c;\u56e0\u6b64\u53ef\u80fd\u4f5c\u4e3a\u5f02\u5e38\u60c5\u51b5\u5904\u7406&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u786e\u8ba4\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u4e2d\u7684maskBytes\u90fd\u662f\u957f\u5ea6\u4e3a4\u7684\u6570\u7ec4&#xff0c;\u907f\u514d\u6d4b\u8bd5\u672c\u8eab\u5f15\u5165\u9519\u8bef\u3002<\/p>\n<\/li>\n<li>\n<p>\u8003\u8651\u662f\u5426\u8986\u76d6\u66f4\u5927\u7684\u6570\u636e\u91cf&#xff0c;\u4f8b\u5982\u6570\u636e\u957f\u5ea6\u6b63\u597d\u662f4\u7684\u500d\u6570&#xff0c;\u6216\u8005\u975e\u5e38\u5927\u7684\u6570\u636e&#xff0c;\u4ee5\u9a8c\u8bc1\u5faa\u73af\u903b\u8f91\u7684\u6b63\u786e\u6027\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u4f8b\u5982&#xff0c;\u6dfb\u52a0\u4e00\u4e2a\u6d4b\u8bd5\u7528\u4f8b&#xff0c;\u6570\u636e\u957f\u5ea6\u6b63\u597d\u662f4\u5b57\u8282&#xff0c;\u63a9\u7801\u6b63\u786e\u5e94\u7528&#xff1a;<\/p>\n<p><span class=\"token function\">it<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\u5904\u7406\u6b63\u597d4\u5b57\u8282\u7684\u6570\u636e&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p><span class=\"token keyword\">const<\/span> mask <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token number\">0x01<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x02<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x03<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x04<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">const<\/span> data <span class=\"token operator\">&#061;<\/span> Buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">from<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">0x05<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x06<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x07<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x08<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">const<\/span> expected <span class=\"token operator\">&#061;<\/span> Buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">from<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">0x04<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x04<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x04<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x0C<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ 0x01^0x05&#061;0x04, 0x02^0x06&#061;0x04, 0x03^0x07&#061;0x04, 0x04^0x08&#061;0x0C<\/span><\/p>\n<p>assert<span class=\"token punctuation\">.<\/span><span class=\"token function\">deepStrictEqual<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">unmask<\/span><span class=\"token punctuation\">(<\/span>mask<span class=\"token punctuation\">,<\/span> data<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> expected<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u6216\u8005\u6d4b\u8bd5\u6570\u636e\u957f\u5ea6\u4e3a8\u5b57\u8282&#xff0c;\u9a8c\u8bc1\u63a9\u7801\u6b63\u786e\u5faa\u73af\u4e24\u6b21&#xff1a;<\/p>\n<p><span class=\"token function\">it<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\u5904\u74068\u5b57\u8282\u6570\u636e&#xff0c;\u4e24\u6b21\u5faa\u73af\u63a9\u7801&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p><span class=\"token keyword\">const<\/span> mask <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token number\">0x01<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x02<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x03<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x04<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">const<\/span> data <span class=\"token operator\">&#061;<\/span> Buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">from<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">0x05<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x06<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x07<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x08<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x09<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x0A<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x0B<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x0C<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">const<\/span> expected <span class=\"token operator\">&#061;<\/span> Buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">from<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">[<\/span><\/p>\n<p><span class=\"token number\">0x01<\/span> <span class=\"token operator\">^<\/span> <span class=\"token number\">0x05<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token comment\">\/\/ 0x04<\/span><\/p>\n<p><span class=\"token number\">0x02<\/span> <span class=\"token operator\">^<\/span> <span class=\"token number\">0x06<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token comment\">\/\/ 0x04<\/span><\/p>\n<p><span class=\"token number\">0x03<\/span> <span class=\"token operator\">^<\/span> <span class=\"token number\">0x07<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token comment\">\/\/ 0x04<\/span><\/p>\n<p><span class=\"token number\">0x04<\/span> <span class=\"token operator\">^<\/span> <span class=\"token number\">0x08<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token comment\">\/\/ 0x0C<\/span><\/p>\n<p><span class=\"token number\">0x01<\/span> <span class=\"token operator\">^<\/span> <span class=\"token number\">0x09<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token comment\">\/\/ 0x08<\/span><\/p>\n<p><span class=\"token number\">0x02<\/span> <span class=\"token operator\">^<\/span> <span class=\"token number\">0x0A<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token comment\">\/\/ 0x08<\/span><\/p>\n<p><span class=\"token number\">0x03<\/span> <span class=\"token operator\">^<\/span> <span class=\"token number\">0x0B<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token comment\">\/\/ 0x08<\/span><\/p>\n<p><span class=\"token number\">0x04<\/span> <span class=\"token operator\">^<\/span> <span class=\"token number\">0x0C<\/span>  <span class=\"token comment\">\/\/ 0x00<\/span><\/p>\n<p><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>assert<span class=\"token punctuation\">.<\/span><span class=\"token function\">deepStrictEqual<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">unmask<\/span><span class=\"token punctuation\">(<\/span>mask<span class=\"token punctuation\">,<\/span> data<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> expected<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u6b64\u5916&#xff0c;\u53ef\u80fd\u9700\u8981\u6d4b\u8bd5\u63a9\u7801\u4e2d\u7684\u67d0\u4e9b\u5b57\u8282\u4e3a0\u7684\u60c5\u51b5&#xff0c;\u4f8b\u5982\u63a9\u7801\u4e2d\u95f4\u6709\u96f6&#xff0c;\u4f46\u4e4b\u524d\u7684\u6d4b\u8bd5\u7528\u4f8b\u5df2\u7ecf\u8986\u76d6\u4e86\u5168\u96f6\u7684\u60c5\u51b5&#xff0c;\u53ef\u80fd\u4e0d\u9700\u8981\u7279\u522b\u6d4b\u8bd5\u3002<\/p>\n<p>\u53e6\u4e00\u4e2a\u53ef\u80fd\u7684\u6d4b\u8bd5\u70b9\u662f\u5f53\u6570\u636e\u957f\u5ea6\u4e3a0\u65f6&#xff0c;\u867d\u7136\u5df2\u7ecf\u6709\u4e00\u4e2a\u6d4b\u8bd5\u7528\u4f8b&#xff0c;\u4f46\u786e\u8ba4\u662f\u5426\u6b63\u786e\u5904\u7406\u3002<\/p>\n<p>\u53e6\u5916&#xff0c;\u786e\u4fdd\u5728\u89e3\u63a9\u540e\u7684\u6570\u636e\u4e0e\u539f\u59cb\u6570\u636e\u5728\u5e94\u7528\u63a9\u7801\u540e\u662f\u5426\u4e00\u81f4\u3002\u4f8b\u5982&#xff0c;\u5982\u679c\u539f\u59cb\u6570\u636e\u662fpayload&#xff0c;\u5e94\u7528\u63a9\u7801\u5f97\u5230maskedData&#xff0c;\u518d\u89e3\u63a9\u5e94\u8be5\u5f97\u5230payload\u3002\u53ef\u4ee5\u7f16\u5199\u4e00\u4e2a\u6d4b\u8bd5\u7528\u4f8b&#xff0c;\u968f\u673a\u751f\u6210\u6570\u636e\u548c\u63a9\u7801&#xff0c;\u9a8c\u8bc1\u4e24\u6b21\u5e94\u7528\u540e\u6062\u590d\u539f\u6570\u636e&#xff1a;<\/p>\n<p><span class=\"token function\">it<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\u89e3\u63a9\u540e\u5e94\u8fd8\u539f\u539f\u59cb\u6570\u636e&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">function<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p><span class=\"token keyword\">const<\/span> mask <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token number\">0x37<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0xFA<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x21<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x3D<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">const<\/span> originalData <span class=\"token operator\">&#061;<\/span> Buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">from<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;Hello World&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;utf8&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u5e94\u7528\u63a9\u7801<\/span><\/p>\n<p><span class=\"token keyword\">const<\/span> maskedData <span class=\"token operator\">&#061;<\/span> Buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">alloc<\/span><span class=\"token punctuation\">(<\/span>originalData<span class=\"token punctuation\">.<\/span>length<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">let<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&lt;<\/span> originalData<span class=\"token punctuation\">.<\/span>length<span class=\"token punctuation\">;<\/span> i<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>maskedData<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> originalData<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">^<\/span> mask<span class=\"token punctuation\">[<\/span>i <span class=\"token operator\">%<\/span> <span class=\"token number\">4<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u89e3\u63a9<\/span><\/p>\n<p><span class=\"token keyword\">const<\/span> unmaskedData <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">unmask<\/span><span class=\"token punctuation\">(<\/span>mask<span class=\"token punctuation\">,<\/span> maskedData<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>assert<span class=\"token punctuation\">.<\/span><span class=\"token function\">deepStrictEqual<\/span><span class=\"token punctuation\">(<\/span>unmaskedData<span class=\"token punctuation\">,<\/span> originalData<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8fd9\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u53ef\u4ee5\u9a8c\u8bc1\u51fd\u6570\u662f\u5426\u6b63\u786e\u5730\u53cc\u5411\u5e94\u7528\u63a9\u7801&#xff0c;\u56e0\u4e3a\u5f02\u6216\u64cd\u4f5c\u662f\u53ef\u9006\u7684\u3002<\/p>\n<p>\u7efc\u4e0a\u6240\u8ff0&#xff0c;\u73b0\u6709\u7684\u6d4b\u8bd5\u7528\u4f8b\u5df2\u7ecf\u5f88\u597d&#xff0c;\u4f46\u53ef\u4ee5\u8fdb\u4e00\u6b65\u8865\u5145\u4e00\u4e9b\u8fb9\u7f18\u60c5\u51b5&#xff0c;\u5982\u6b63\u597d4\u5b57\u8282\u7684\u6570\u636e\u3001\u591a\u6b21\u5faa\u73af\u63a9\u7801\u7684\u6570\u636e&#xff0c;\u4ee5\u53ca\u9a8c\u8bc1\u53cc\u5411\u5e94\u7528\u7684\u6b63\u786e\u6027\u3002\u540c\u65f6&#xff0c;\u8003\u8651\u5230WebSocket\u534f\u8bae\u7684\u8981\u6c42&#xff0c;\u53ef\u80fd\u4e0d\u9700\u8981\u6d4b\u8bd5\u975e\u6cd5\u63a9\u7801\u957f\u5ea6&#xff0c;\u4f46\u5982\u679c\u6709\u9700\u8981&#xff0c;\u53ef\u4ee5\u6dfb\u52a0\u76f8\u5e94\u7684\u6d4b\u8bd5\u7528\u4f8b\u6765\u786e\u4fdd\u51fd\u6570\u5728\u975e\u6cd5\u8f93\u5165\u65f6\u7684\u884c\u4e3a&#xff08;\u5982\u629b\u51fa\u9519\u8bef&#xff09;\u3002<\/p>\n<p><span class=\"token comment\">\/\/\u8fd9\u4e2a\u63a9\u7801\u53ef\u4ee5\u6539,\u8fdb\u884c\u63a9\u7801\u6216\u89e3\u7801\u65f6&#xff0c;\u8fd9\u4e2a\u5fc5\u987b\u8981\u4e00\u6837<\/span><br \/>\n<span class=\"token keyword\">let<\/span> maskBytes<span class=\"token operator\">&#061;<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">0x55<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0xAA<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0x33<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0xCC<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/\u6570\u636e\u53ef\u4ee5\u662f\u4efb\u4f55\u6570\u636e\u6216\u5b57\u7b26\u7b49<\/span><br \/>\n<span class=\"token keyword\">let<\/span> data<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;hello wrold&#034;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/\u6570\u636e\u8fdb\u884c\u89e3\u7801\u51fd\u6570<\/span><br \/>\n<span class=\"token keyword\">let<\/span> <span class=\"token function-variable function\">unmask<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token keyword\">function<\/span><span class=\"token punctuation\">(<\/span><span class=\"token parameter\">maskBytes<span class=\"token punctuation\">,<\/span>data<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">let<\/span> payload<span class=\"token operator\">&#061;<\/span>Buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">alloc<\/span><span class=\"token punctuation\">(<\/span>data<span class=\"token punctuation\">.<\/span>length<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">for<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">let<\/span> i<span class=\"token operator\">&#061;<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span>i<span class=\"token operator\">&lt;<\/span>data<span class=\"token punctuation\">.<\/span>length<span class=\"token punctuation\">;<\/span>i<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        payload<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token operator\">&#061;<\/span>maskBytes<span class=\"token punctuation\">[<\/span>i<span class=\"token operator\">%<\/span><span class=\"token number\">4<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">^<\/span> data<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> payload<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/\u6570\u636e\u8fdb\u884c\u63a9\u7801\u51fd\u6570<\/span><br \/>\n<span class=\"token keyword\">let<\/span> <span class=\"token function-variable function\">masked<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token keyword\">function<\/span><span class=\"token punctuation\">(<\/span><span class=\"token parameter\">maskBytes<span class=\"token punctuation\">,<\/span>data<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">let<\/span> d<span class=\"token operator\">&#061;<\/span>Buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">from<\/span><span class=\"token punctuation\">(<\/span>data<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">let<\/span> dataload<span class=\"token operator\">&#061;<\/span>Buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">alloc<\/span><span class=\"token punctuation\">(<\/span>d<span class=\"token punctuation\">.<\/span>length<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">for<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">let<\/span> i<span class=\"token operator\">&#061;<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span>i<span class=\"token operator\">&lt;<\/span>d<span class=\"token punctuation\">.<\/span>length<span class=\"token punctuation\">;<\/span>i<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        dataload<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token operator\">&#061;<\/span>d<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">^<\/span> maskBytes<span class=\"token punctuation\">[<\/span>i<span class=\"token operator\">%<\/span><span class=\"token number\">4<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/const maskData&#061;Buffer.from(d.map((b,i)&#061;&gt;b^maskBytes[i%4]));<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> dataload<span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token comment\">\/\/\u8fdb\u884c\u63a9\u7801<\/span><br \/>\n<span class=\"token keyword\">let<\/span> maskedData<span class=\"token operator\">&#061;<\/span><span class=\"token function\">masked<\/span><span class=\"token punctuation\">(<\/span>maskBytes<span class=\"token punctuation\">,<\/span>data<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/\u5bf9maskedData\u8fdb\u884c\u89e3\u7801<\/span><br \/>\nconsole<span class=\"token punctuation\">.<\/span><span class=\"token function\">log<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">unmask<\/span><span class=\"token punctuation\">(<\/span>maskBytes<span class=\"token punctuation\">,<\/span>maskedData<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">toString<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e15\u6b21\uff0c\u6536\u85cf13\u6b21\u3002\u4f46\u5728WebSocket\u534f\u8bae\u7684\u4e0a\u4e0b\u6587\u4e2d\uff0cmaskBytes\u5e94\u8be5\u662f4\u4e2a\u5b57\u8282\u7684\u6570\u7ec4\uff0c\u6bcf\u4e2a\u5143\u7d20\u662f0-255\u7684\u6574\u6570\uff0c\u56e0\u6b64\u8fd9\u79cd\u60c5\u51b5\u5e94\u7531\u4e0a\u5c42\u8f93\u5165\u9a8c\u8bc1\u5904\u7406\uff0c\u800c\u4e0d\u662f\u5728unmask\u51fd\u6570\u4e2d\u5904\u7406\u3002\u4f46\u6839\u636eWebSocket\u534f\u8bae\uff0c\u670d\u52a1\u5668\u5728\u63a5\u6536\u5230\u5ba2\u6237\u7aef\u6d88\u606f\u65f6\uff0c\u63a9\u7801\u5fc5\u987b\u662f4\u5b57\u8282\uff0c\u56e0\u6b64\u5728\u6b63\u786e\u7684\u5b9e\u73b0\u4e2d\uff0c\u8c03\u7528unmask\u51fd\u6570\u4e4b\u524d\uff0c\u5e94\u8be5\u5df2\u7ecf\u9a8c\u8bc1\u4e86maskBytes\u7684\u957f\u5ea6\u4e3a4\u3002\u6b64\u5916\uff0c\u53ef\u80fd\u9700\u8981\u6d4b\u8bd5\u63a9\u7801\u4e2d\u7684\u67d0\u4e9b\u5b57\u8282\u4e3a0\u7684\u60c5\u51b5\uff0c\u4f8b\u5982\u63a9\u7801\u4e2d\u95f4\u6709\u96f6\uff0c\u4f46\u4e4b\u524d\u7684\u6d4b\u8bd5\u7528\u4f8b\u5df2\u7ecf\u8986\u76d6\u4e86\u5168\u96f6\u7684\u60c5\u51b5\uff0c\u53ef\u80fd\u4e0d\u9700\u8981\u7279\u522b\u6d4b\u8bd5\u3002\uff1a\u5bf9\u4e8e\u5927\u6570\u636e\u91cf\u7684\u5904\u7406\uff0c\u662f\u5426\u6709\u6548\u7387\u95ee\u9898\uff1f_websocket\u7684\u63a9\u7801<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1282,947,43,78],"topic":[],"class_list":["post-17313","post","type-post","status-publish","format-standard","hentry","category-server","tag-nodejs","tag-websocket","tag-43","tag-78"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>WebSocket\u534f\u8bae\u91cc\u5ba2\u6237\u7aef\u53d1\u9001\u7ed9\u670d\u52a1\u5668\u7684\u6570\u636e\u4f1a\u75284\u5b57\u8282\u7684\u63a9\u7801\u5faa\u73af\u5f02\u6216\u7684\u5206\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/17313.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WebSocket\u534f\u8bae\u91cc\u5ba2\u6237\u7aef\u53d1\u9001\u7ed9\u670d\u52a1\u5668\u7684\u6570\u636e\u4f1a\u75284\u5b57\u8282\u7684\u63a9\u7801\u5faa\u73af\u5f02\u6216\u7684\u5206\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e15\u6b21\uff0c\u6536\u85cf13\u6b21\u3002\u4f46\u5728WebSocket\u534f\u8bae\u7684\u4e0a\u4e0b\u6587\u4e2d\uff0cmaskBytes\u5e94\u8be5\u662f4\u4e2a\u5b57\u8282\u7684\u6570\u7ec4\uff0c\u6bcf\u4e2a\u5143\u7d20\u662f0-255\u7684\u6574\u6570\uff0c\u56e0\u6b64\u8fd9\u79cd\u60c5\u51b5\u5e94\u7531\u4e0a\u5c42\u8f93\u5165\u9a8c\u8bc1\u5904\u7406\uff0c\u800c\u4e0d\u662f\u5728unmask\u51fd\u6570\u4e2d\u5904\u7406\u3002\u4f46\u6839\u636eWebSocket\u534f\u8bae\uff0c\u670d\u52a1\u5668\u5728\u63a5\u6536\u5230\u5ba2\u6237\u7aef\u6d88\u606f\u65f6\uff0c\u63a9\u7801\u5fc5\u987b\u662f4\u5b57\u8282\uff0c\u56e0\u6b64\u5728\u6b63\u786e\u7684\u5b9e\u73b0\u4e2d\uff0c\u8c03\u7528unmask\u51fd\u6570\u4e4b\u524d\uff0c\u5e94\u8be5\u5df2\u7ecf\u9a8c\u8bc1\u4e86maskBytes\u7684\u957f\u5ea6\u4e3a4\u3002\u6b64\u5916\uff0c\u53ef\u80fd\u9700\u8981\u6d4b\u8bd5\u63a9\u7801\u4e2d\u7684\u67d0\u4e9b\u5b57\u8282\u4e3a0\u7684\u60c5\u51b5\uff0c\u4f8b\u5982\u63a9\u7801\u4e2d\u95f4\u6709\u96f6\uff0c\u4f46\u4e4b\u524d\u7684\u6d4b\u8bd5\u7528\u4f8b\u5df2\u7ecf\u8986\u76d6\u4e86\u5168\u96f6\u7684\u60c5\u51b5\uff0c\u53ef\u80fd\u4e0d\u9700\u8981\u7279\u522b\u6d4b\u8bd5\u3002\uff1a\u5bf9\u4e8e\u5927\u6570\u636e\u91cf\u7684\u5904\u7406\uff0c\u662f\u5426\u6709\u6548\u7387\u95ee\u9898\uff1f_websocket\u7684\u63a9\u7801\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/17313.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T15:46:58+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/17313.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/17313.html\",\"name\":\"WebSocket\u534f\u8bae\u91cc\u5ba2\u6237\u7aef\u53d1\u9001\u7ed9\u670d\u52a1\u5668\u7684\u6570\u636e\u4f1a\u75284\u5b57\u8282\u7684\u63a9\u7801\u5faa\u73af\u5f02\u6216\u7684\u5206\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T15:46:58+00:00\",\"dateModified\":\"2025-04-18T15:46:58+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/17313.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/17313.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/17313.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WebSocket\u534f\u8bae\u91cc\u5ba2\u6237\u7aef\u53d1\u9001\u7ed9\u670d\u52a1\u5668\u7684\u6570\u636e\u4f1a\u75284\u5b57\u8282\u7684\u63a9\u7801\u5faa\u73af\u5f02\u6216\u7684\u5206\u6790\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WebSocket\u534f\u8bae\u91cc\u5ba2\u6237\u7aef\u53d1\u9001\u7ed9\u670d\u52a1\u5668\u7684\u6570\u636e\u4f1a\u75284\u5b57\u8282\u7684\u63a9\u7801\u5faa\u73af\u5f02\u6216\u7684\u5206\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/17313.html","og_locale":"zh_CN","og_type":"article","og_title":"WebSocket\u534f\u8bae\u91cc\u5ba2\u6237\u7aef\u53d1\u9001\u7ed9\u670d\u52a1\u5668\u7684\u6570\u636e\u4f1a\u75284\u5b57\u8282\u7684\u63a9\u7801\u5faa\u73af\u5f02\u6216\u7684\u5206\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e15\u6b21\uff0c\u6536\u85cf13\u6b21\u3002\u4f46\u5728WebSocket\u534f\u8bae\u7684\u4e0a\u4e0b\u6587\u4e2d\uff0cmaskBytes\u5e94\u8be5\u662f4\u4e2a\u5b57\u8282\u7684\u6570\u7ec4\uff0c\u6bcf\u4e2a\u5143\u7d20\u662f0-255\u7684\u6574\u6570\uff0c\u56e0\u6b64\u8fd9\u79cd\u60c5\u51b5\u5e94\u7531\u4e0a\u5c42\u8f93\u5165\u9a8c\u8bc1\u5904\u7406\uff0c\u800c\u4e0d\u662f\u5728unmask\u51fd\u6570\u4e2d\u5904\u7406\u3002\u4f46\u6839\u636eWebSocket\u534f\u8bae\uff0c\u670d\u52a1\u5668\u5728\u63a5\u6536\u5230\u5ba2\u6237\u7aef\u6d88\u606f\u65f6\uff0c\u63a9\u7801\u5fc5\u987b\u662f4\u5b57\u8282\uff0c\u56e0\u6b64\u5728\u6b63\u786e\u7684\u5b9e\u73b0\u4e2d\uff0c\u8c03\u7528unmask\u51fd\u6570\u4e4b\u524d\uff0c\u5e94\u8be5\u5df2\u7ecf\u9a8c\u8bc1\u4e86maskBytes\u7684\u957f\u5ea6\u4e3a4\u3002\u6b64\u5916\uff0c\u53ef\u80fd\u9700\u8981\u6d4b\u8bd5\u63a9\u7801\u4e2d\u7684\u67d0\u4e9b\u5b57\u8282\u4e3a0\u7684\u60c5\u51b5\uff0c\u4f8b\u5982\u63a9\u7801\u4e2d\u95f4\u6709\u96f6\uff0c\u4f46\u4e4b\u524d\u7684\u6d4b\u8bd5\u7528\u4f8b\u5df2\u7ecf\u8986\u76d6\u4e86\u5168\u96f6\u7684\u60c5\u51b5\uff0c\u53ef\u80fd\u4e0d\u9700\u8981\u7279\u522b\u6d4b\u8bd5\u3002\uff1a\u5bf9\u4e8e\u5927\u6570\u636e\u91cf\u7684\u5904\u7406\uff0c\u662f\u5426\u6709\u6548\u7387\u95ee\u9898\uff1f_websocket\u7684\u63a9\u7801","og_url":"https:\/\/www.wsisp.com\/helps\/17313.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T15:46:58+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/17313.html","url":"https:\/\/www.wsisp.com\/helps\/17313.html","name":"WebSocket\u534f\u8bae\u91cc\u5ba2\u6237\u7aef\u53d1\u9001\u7ed9\u670d\u52a1\u5668\u7684\u6570\u636e\u4f1a\u75284\u5b57\u8282\u7684\u63a9\u7801\u5faa\u73af\u5f02\u6216\u7684\u5206\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T15:46:58+00:00","dateModified":"2025-04-18T15:46:58+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/17313.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/17313.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/17313.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"WebSocket\u534f\u8bae\u91cc\u5ba2\u6237\u7aef\u53d1\u9001\u7ed9\u670d\u52a1\u5668\u7684\u6570\u636e\u4f1a\u75284\u5b57\u8282\u7684\u63a9\u7801\u5faa\u73af\u5f02\u6216\u7684\u5206\u6790"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/17313","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=17313"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/17313\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=17313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=17313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=17313"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=17313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}