{"id":277205,"date":"2024-05-16T15:15:28","date_gmt":"2024-05-16T07:15:28","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/277205.html"},"modified":"2024-05-16T15:15:33","modified_gmt":"2024-05-16T07:15:33","slug":"socket-%e9%a1%b9%e7%9b%ae%e7%b2%98%e5%8c%85%e9%97%ae%e9%a2%98%e7%9a%84%e8%a7%a3%e5%86%b3%e6%96%b9%e6%b3%95%e6%9c%89%e5%93%aa%e4%ba%9b","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/277205.html","title":{"rendered":"Socket \u9879\u76ee\u7c98\u5305\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6cd5\u6709\u54ea\u4e9b"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24202305\/ca1a8061-96b1-4496-9cb9-975dd9f91746.webp\" alt=\"Socket \u9879\u76ee\u7c98\u5305\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6cd5\u6709\u54ea\u4e9b\" \/><\/p>\n<p><p>\u57fa\u4e8eSocket\u9879\u76ee\u4e2d\u6570\u636e\u4f20\u8f93\u7684\u7279\u5b9a\uff0c\u7c98\u5305\u95ee\u9898\u662f\u4e00\u4e2a\u5e38\u89c1\u4e14\u68d8\u624b\u7684\u6280\u672f\u96be\u9898\u3002<strong>\u89e3\u51b3\u7c98\u5305\u95ee\u9898\u7684\u65b9\u6cd5\u4e3b\u8981\u5305\u62ec\uff1a\u4f7f\u7528\u56fa\u5b9a\u957f\u5ea6\u7684\u6d88\u606f\u3001\u6d88\u606f\u5b9a\u754c\u7b26\u3001\u6d88\u606f\u957f\u5ea6\u5b57\u6bb5\u3001TCP\u7c98\u5305\u5904\u7406\u7b56\u7565<\/strong>\u3002\u5728\u8fd9\u4e9b\u65b9\u6cd5\u4e2d\uff0c<strong>\u6d88\u606f\u957f\u5ea6\u5b57\u6bb5<\/strong>\u662f\u5e7f\u6cdb\u5e94\u7528\u7684\u4e00\u79cd\u65b9\u6848\uff0c\u5b83\u901a\u8fc7\u5728\u6bcf\u4e2a\u6d88\u606f\u5f00\u59cb\u5904\u5305\u542b\u4e00\u4e2a\u8868\u793a\u6d88\u606f\u957f\u5ea6\u7684\u5b57\u6bb5\uff0c\u4f7f\u5f97\u63a5\u6536\u65b9\u80fd\u591f\u51c6\u786e\u77e5\u9053\u6bcf\u4e2a\u72ec\u7acb\u6d88\u606f\u7684\u8fb9\u754c\uff0c\u8fdb\u800c\u6b63\u786e\u5730\u5904\u7406\u548c\u89e3\u6790\u6d88\u606f\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u56fa\u5b9a\u957f\u5ea6\u7684\u6d88\u606f<\/h3>\n<\/p>\n<p><p><strong>\u56fa\u5b9a\u957f\u5ea6\u7684\u6d88\u606f<\/strong>\u662f\u4e00\u79cd\u6700\u7b80\u5355\u7684\u89e3\u51b3\u7c98\u5305\u95ee\u9898\u7684\u65b9\u5f0f\uff0c\u5b83\u8981\u6c42\u6bcf\u4e2a\u6d88\u606f\u7684\u5927\u5c0f\u90fd\u662f\u56fa\u5b9a\u7684\u3002<\/p>\n<\/p>\n<ul>\n<li>\u5728\u53d1\u9001\u65b9\uff0c\u4e0d\u8db3\u56fa\u5b9a\u957f\u5ea6\u7684\u6570\u636e\u9700\u8981\u5728\u540e\u9762\u8865\u5145\u7279\u5b9a\u7684\u586b\u5145\u5b57\u7b26\u3002<\/li>\n<li>\u63a5\u6536\u65b9\u6839\u636e\u56fa\u5b9a\u957f\u5ea6\u6765\u8bfb\u53d6\u6570\u636e\uff0c\u4ece\u800c\u907f\u514d\u7c98\u5305\u95ee\u9898\u3002<\/li>\n<\/ul>\n<p><p>\u8be5\u65b9\u6cd5\u5b9e\u73b0\u7b80\u5355\uff0c\u4f46\u662f\u5728\u6570\u636e\u4f20\u8f93\u7684\u9ad8\u6548\u6027\u4e0a\u4e0d\u591f\u7075\u6d3b\uff0c\u53ef\u80fd\u4f1a\u9020\u6210\u5e26\u5bbd\u7684\u6d6a\u8d39\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u6d88\u606f\u5b9a\u754c\u7b26<\/h3>\n<\/p>\n<p><p><strong>\u6d88\u606f\u5b9a\u754c\u7b26<\/strong>\u662f\u53e6\u4e00\u79cd\u89e3\u51b3\u7c98\u5305\u95ee\u9898\u7684\u7b56\u7565\uff0c\u901a\u5e38\u7528\u4e8e\u6587\u672c\u534f\u8bae\u3002<\/p>\n<\/p>\n<ul>\n<li>\u53d1\u9001\u65b9\u5728\u6bcf\u4e2a\u6d88\u606f\u7684\u672b\u5c3e\u6dfb\u52a0\u7279\u5b9a\u7684\u5b57\u7b26\u6216\u5b57\u7b26\u4e32\u4f5c\u4e3a\u6d88\u606f\u7684\u7ed3\u675f\u7b26\u3002<\/li>\n<li>\u63a5\u6536\u65b9\u901a\u8fc7\u8bfb\u53d6\u6570\u636e\u76f4\u5230\u9047\u5230\u7ed3\u675f\u7b26\uff0c\u4ece\u4e2d\u8bc6\u522b\u51fa\u6d88\u606f\u7684\u8fb9\u754c\u3002<\/li>\n<\/ul>\n<p><p>\u8be5\u65b9\u6cd5\u5728\u6d88\u606f\u5185\u5bb9\u4e0d\u5305\u542b\u5b9a\u754c\u7b26\u7684\u60c5\u51b5\u4e0b\u975e\u5e38\u6709\u6548\uff0c\u4f46\u5982\u5b9a\u754c\u7b26\u5728\u6d88\u606f\u5185\u5bb9\u4e2d\u53ef\u80fd\u51fa\u73b0\uff0c\u5219\u9700\u8981\u6d88\u606f\u5185\u5bb9\u8fdb\u884c\u8f6c\u4e49\u5904\u7406\uff0c\u589e\u52a0\u4e86\u590d\u6742\u6027\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u6d88\u606f\u957f\u5ea6\u5b57\u6bb5<\/h3>\n<\/p>\n<p><p><strong>\u4f7f\u7528\u6d88\u606f\u957f\u5ea6\u5b57\u6bb5<\/strong>\u662f\u4e00\u79cd\u975e\u5e38\u9ad8\u6548\u4e14\u88ab\u5e7f\u6cdb\u4f7f\u7528\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u5c24\u5176\u9002\u7528\u4e8e\u4e8c\u8fdb\u5236\u534f\u8bae\u3002<\/p>\n<\/p>\n<ul>\n<li>\u53d1\u9001\u65b9\u5728\u6d88\u606f\u524d\u9644\u52a0\u4e00\u4e2a\u957f\u5ea6\u5b57\u6bb5\uff0c\u6307\u793a\u6d88\u606f\u5185\u5bb9\u7684\u957f\u5ea6\u3002<\/li>\n<li>\u63a5\u6536\u65b9\u9996\u5148\u8bfb\u53d6\u957f\u5ea6\u5b57\u6bb5\uff0c\u7136\u540e\u6839\u636e\u8be5\u957f\u5ea6\u8bfb\u53d6\u76f8\u5e94\u6570\u91cf\u7684\u6570\u636e\u3002<\/li>\n<\/ul>\n<p><p>\u8be5\u7b56\u7565\u80fd\u591f\u660e\u786e\u5206\u9694\u6d88\u606f\uff0c\u5904\u7406\u7075\u6d3b\u4e14\u6548\u7387\u9ad8\uff0c\u5e38\u89c1\u4e8e\u5404\u79cd\u7f51\u7edc\u901a\u4fe1\u534f\u8bae\u4e2d\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001TCP\u7c98\u5305\u5904\u7406\u7b56\u7565<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528TCP\u534f\u8bae\u8fdb\u884c\u901a\u4fe1\u65f6\uff0c<strong>TCP\u7c98\u5305\u5904\u7406\u7b56\u7565<\/strong>\u662f\u7406\u89e3\u548c\u5e94\u7528\u7684\u5173\u952e\u3002<\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528\u975e\u963b\u585eIO(NIO)\uff0c\u7ed3\u5408\u9009\u62e9\u5668(selector)\u76d1\u542c\u8bfb\u53d6\u4e8b\u4ef6\uff0c\u5f53\u6709\u6570\u636e\u53ef\u8bfb\u65f6\u8fdb\u884c\u5904\u7406\u3002<\/li>\n<li>\u91c7\u7528\u201c\u8bfb\u53d6-\u5904\u7406-\u5b58\u50a8\u201d\u6d41\u7a0b\uff0c\u5bf9\u8bfb\u53d6\u5230\u7684\u6570\u636e\u8fdb\u884c\u4e34\u65f6\u5b58\u50a8\uff0c\u5206\u6790\u6570\u636e\u5b8c\u6574\u6027\u540e\u518d\u8fdb\u884c\u4e1a\u52a1\u5904\u7406\u3002<\/li>\n<\/ul>\n<p><p>\u672c\u90e8\u5206\u6838\u5fc3\u5185\u5bb9\u52a0\u7c97\u6807\u6ce8\uff0c\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u89e3\u51b3Socket\u9879\u76ee\u4e2d\u7c98\u5305\u95ee\u9898\u5e38\u89c1\u7684\u51e0\u79cd\u65b9\u6cd5\u3002\u63a5\u4e0b\u6765\uff0c\u6587\u7ae0\u5c06\u8be6\u7ec6\u63a2\u8ba8\u6bcf\u4e00\u79cd\u65b9\u6cd5\u7684\u5177\u4f53\u5b9e\u73b0\u548c\u5e94\u7528\u573a\u666f\uff0c\u4ee5\u53ca\u5b83\u4eec\u5404\u81ea\u7684\u4f18\u52bf\u548c\u9650\u5236\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>Q1: \u4e3a\u4ec0\u4e48Socket\u9879\u76ee\u4e2d\u4f1a\u51fa\u73b0\u7c98\u5305\u95ee\u9898\uff1f<\/strong><\/p>\n<p>\u5728Socket\u901a\u4fe1\u4e2d\uff0c\u7531\u4e8e\u6570\u636e\u662f\u4ee5\u4e8c\u8fdb\u5236\u6d41\u7684\u5f62\u5f0f\u8fdb\u884c\u4f20\u8f93\uff0c\u53d1\u9001\u7aef\u5f80\u5f80\u4f1a\u5c06\u591a\u4e2a\u5c0f\u6570\u636e\u5305\u5408\u5e76\u6210\u4e00\u4e2a\u5927\u7684\u6570\u636e\u5305\u8fdb\u884c\u53d1\u9001\uff0c\u800c\u63a5\u6536\u7aef\u53ef\u80fd\u65e0\u6cd5\u51c6\u786e\u5730\u5206\u8fa8\u51fa\u6bcf\u4e2a\u6570\u636e\u5305\u7684\u8fb9\u754c\uff0c\u4ece\u800c\u5bfc\u81f4\u7c98\u5305\u95ee\u9898\u7684\u51fa\u73b0\u3002<\/p>\n<p><strong>Q2: \u6709\u54ea\u4e9b\u5e38\u89c1\u7684\u89e3\u51b3Socket\u9879\u76ee\u7c98\u5305\u95ee\u9898\u7684\u65b9\u6cd5\uff1f<\/strong><\/p>\n<ul>\n<li>\u65b9\u6cd5\u4e00\uff1a\u4f7f\u7528\u6d88\u606f\u673a\u5236\uff0c\u901a\u8fc7\u4e3a\u6bcf\u4e2a\u6570\u636e\u5305\u6dfb\u52a0\u6d88\u606f\u5934\uff0c\u5305\u542b\u6570\u636e\u957f\u5ea6\u7b49\u4fe1\u606f\uff0c\u63a5\u6536\u7aef\u6839\u636e\u6d88\u606f\u5934\u6765\u51c6\u786e\u5730\u622a\u53d6\u6bcf\u4e2a\u6570\u636e\u5305\uff0c\u907f\u514d\u7c98\u5305\u95ee\u9898\u3002<\/li>\n<li>\u65b9\u6cd5\u4e8c\uff1a\u4f7f\u7528\u5206\u9694\u7b26\uff0c\u53d1\u9001\u7aef\u5728\u6bcf\u4e2a\u6570\u636e\u5305\u7684\u672b\u5c3e\u6dfb\u52a0\u4e00\u4e2a\u7279\u6b8a\u7684\u5206\u9694\u7b26\uff0c\u63a5\u6536\u7aef\u6839\u636e\u5206\u9694\u7b26\u5c06\u6570\u636e\u5206\u5272\u6210\u72ec\u7acb\u7684\u6570\u636e\u5305\uff0c\u907f\u514d\u7c98\u5305\u95ee\u9898\u3002<\/li>\n<li>\u65b9\u6cd5\u4e09\uff1a\u4f7f\u7528\u5b9a\u957f\u6570\u636e\u5305\uff0c\u6307\u5b9a\u6bcf\u4e2a\u6570\u636e\u5305\u7684\u56fa\u5b9a\u957f\u5ea6\uff0c\u63a5\u6536\u7aef\u6839\u636e\u56fa\u5b9a\u957f\u5ea6\u6765\u622a\u53d6\u6bcf\u4e2a\u6570\u636e\u5305\uff0c\u907f\u514d\u7c98\u5305\u95ee\u9898\u3002<\/li>\n<\/ul>\n<p><strong>Q3: \u5728Socket\u9879\u76ee\u4e2d\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684\u89e3\u51b3\u7c98\u5305\u95ee\u9898\u7684\u65b9\u6cd5\uff1f<\/strong><\/p>\n<p>\u9009\u62e9\u5408\u9002\u7684\u89e3\u51b3\u7c98\u5305\u95ee\u9898\u7684\u65b9\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u5e94\u7528\u573a\u666f\u548c\u9700\u6c42\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u5bf9\u6570\u636e\u5305\u5927\u5c0f\u8981\u6c42\u8f83\u9ad8\uff0c\u4e14\u4f20\u8f93\u7684\u6570\u636e\u6bd4\u8f83\u7a33\u5b9a\uff0c\u53ef\u4ee5\u9009\u62e9\u5b9a\u957f\u6570\u636e\u5305\u7684\u65b9\u5f0f\uff1b<\/li>\n<li>\u5982\u679c\u4f20\u8f93\u7684\u6570\u636e\u5927\u5c0f\u4e0d\u56fa\u5b9a\uff0c\u4e14\u5bf9\u6570\u636e\u5305\u7684\u5b8c\u6574\u6027\u8981\u6c42\u8f83\u9ad8\uff0c\u53ef\u4ee5\u9009\u62e9\u4f7f\u7528\u6d88\u606f\u673a\u5236\uff1b<\/li>\n<li>\u5982\u679c\u4f20\u8f93\u7684\u6570\u636e\u4e2d\u5305\u542b\u4e00\u4e9b\u7279\u6b8a\u7684\u5206\u9694\u7b26\u6216\u63a7\u5236\u7b26\uff0c\u53ef\u4ee5\u9009\u62e9\u4f7f\u7528\u5206\u9694\u7b26\u7684\u65b9\u5f0f\u6765\u89e3\u51b3\u7c98\u5305\u95ee\u9898\u3002<\/li>\n<\/ul>\n<p>\u7efc\u5408\u8003\u8651\u5e94\u7528\u7684\u5177\u4f53\u60c5\u51b5\uff0c\u9009\u62e9\u6700\u9002\u5408\u7684\u89e3\u51b3\u65b9\u6cd5\u53ef\u4ee5\u6709\u6548\u5730\u89e3\u51b3Socket\u9879\u76ee\u7c98\u5305\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u57fa\u4e8eSocket\u9879\u76ee\u4e2d\u6570\u636e\u4f20\u8f93\u7684\u7279\u5b9a\uff0c\u7c98\u5305\u95ee\u9898\u662f\u4e00\u4e2a\u5e38\u89c1\u4e14\u68d8\u624b\u7684\u6280\u672f\u96be\u9898\u3002\u89e3\u51b3\u7c98\u5305\u95ee\u9898\u7684\u65b9\u6cd5\u4e3b\u8981\u5305\u62ec\uff1a\u4f7f\u7528\u56fa\u5b9a [&hellip;]","protected":false},"author":3,"featured_media":277210,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/277205"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=277205"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/277205\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/277210"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=277205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=277205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=277205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}