{"id":184,"date":"2025-10-18T17:59:41","date_gmt":"2025-10-18T09:59:41","guid":{"rendered":"http:\/\/47.99.178.170\/?p=184"},"modified":"2025-10-23T21:56:31","modified_gmt":"2025-10-23T13:56:31","slug":"socket%e8%bf%9e%e6%8e%a5%e6%b5%81%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.garfield-blog.top\/?p=184","title":{"rendered":"\u3010\u8ba1\u7b97\u673a\u7f51\u7edc\u3011Socket(2) \u8fde\u63a5\u6d41\u7a0b"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">Socket\u8fde\u63a5\u6d41\u7a0b<\/h1>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u53c2\u8003\u6587\u6863<\/p>\n\n\n\n<p><a href=\"https:\/\/www.51cto.com\/article\/742745.html\">Socket\u5230\u5e95\u662f\u4ec0\u4e48\uff1f\u4f60\u60f3\u77e5\u9053\u5417\uff1f-socket\u662f\u4ec0\u4e48\u610f\u601d (51cto.com)<\/a><\/p>\n\n\n\n<p>[wiki\u767e\u79d1socket]<a href=\"https:\/\/zh.wikipedia.org\/wiki\/%E7%B6%B2%E8%B7%AF%E6%8F%92%E5%BA%A7\">https:\/\/zh.wikipedia.org\/wiki\/%E7%B6%B2%E8%B7%AF%E6%8F%92%E5%BA%A7<\/a><\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">\u7c7b\u578b<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6570\u636e\u62a5\u5957\u63a5\u5b57\uff08<code>SOCK_DGRAM<\/code>\uff09<\/strong><\/li>\n<\/ol>\n\n\n\n<p>\u6570\u636e\u62a5\u5957\u63a5\u5b57\u662f\u4e00\u79cd\u65e0\u8fde\u5957\u63a5\u5b57\u63a5\u5b57\uff0c\u4f7f\u7528\u7528\u6237\u6570\u636e\u62a5\u534f\u8bae\uff08<code>UDP<\/code>\uff09\u4f20\u8f93\u6570\u636e\u3002\u6bcf\u4e00\u4e2a\u6570\u636e\u5305\u90fd\u5355\u72ec\u5bfb\u5740\u548c\u8def\u7531\u3002\u8fd9\u5bfc\u81f4\u4e86\u63a5\u6536\u7aef\u63a5\u6536\u5230\u7684\u6570\u636e\u53ef\u80fd\u662f\u4e71\u5e8f\u7684\uff0c\u6709\u4e00\u4e9b\u6570\u636e\u751a\u81f3\u53ef\u80fd\u4f1a\u5728\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u4e22\u5931\u3002\u4e0d\u8fc7\u5f97\u76ca\u4e8e\u6570\u636e\u62a5\u5957\u63a5\u5b57\u5e76\u4e0d\u9700\u8981\u5efa\u7acb\u5e76\u7ef4\u62a4\u4e00\u4e2a\u7a33\u5b9a\u7684\u8fde\u63a5\uff0c\u6570\u636e\u62a5\u5957\u63a5\u5b57\u6240\u5360\u7528\u7684\u8ba1\u7b97\u673a\u548c\u7cfb\u7edf\u8d44\u6e90\u8f83\u5c0f\u3002<\/p>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u6d41\u5957\u63a5\u5b57\uff08<code>SOCK_STREAM<\/code>\uff09<\/strong>\u8fde\u63a5\u5bfc\u5411\u5f0f\u901a\u4fe1\u5957\u63a5\u5b57\uff0c\u4f7f\u7528\u4f20\u8f93\u63a7\u5236\u534f\u8bae\uff08<code>TCP<\/code>\uff09\u3001\u6d41\u63a7\u5236\u4f20\u8f93\u534f\u8bae\uff08<code>SCTP<\/code>\uff09\u6216\u8005\u6570\u636e\u62e5\u585e\u63a7\u5236\u534f\u8bae\uff08<code>DCCP<\/code>\uff09\u4f20\u8f93\u6570\u636e\u3002\u6d41\u5957\u63a5\u5b57\u63d0\u4f9b\u53ef\u9760\u5e76\u4e14\u6709\u5e8f\u7684\u6570\u636e\u4f20\u8f93\u670d\u52a1\u3002\u5728\u4e92\u8054\u7f51\u4e0a\uff0c\u6d41\u5957\u63a5\u5b57\u901a\u5e38\u4f7f\u7528TCP\u5b9e\u73b0\uff0c\u4ee5\u4fbf\u5e94\u7528\u53ef\u4ee5\u5728\u4efb\u4f55\u4f7f\u7528TCP\/IP\u534f\u8bae\u7684\u7f51\u7edc\u4e0a\u8fd0\u884c\u3002<\/li>\n\n\n\n<li><strong>\u539f\u59cb\u5957\u63a5\u5b57<\/strong>\u539f\u59cb\u5957\u63a5\u5b57\u662f\u4e00\u79cd\u7f51\u7edc\u5957\u63a5\u5b57\u3002\u5141\u8bb8\u76f4\u63a5\u53d1\u9001\u548c\u63a5\u53d7IP\u6570\u636e\u5305\u5e76\u4e14\u4e0d\u9700\u8981\u4efb\u4f55\u4f20\u8f93\u5c42\u534f\u8bae\u683c\u5f0f\u3002\u539f\u59cb\u5957\u63a5\u5b57\u4e3b\u8981\u7528\u4e8e\u4e00\u4e9b\u534f\u8bae\u7684\u5f00\u53d1\uff0c\u53ef\u4ee5\u8fdb\u884c\u6bd4\u8f83\u5e95\u5c42\u7684\u64cd\u4f5c\u3002<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">socket\u6d41\u7a0b<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.garfield-blog.top\/wp-content\/uploads\/2025\/10\/socket\u8fde\u63a5\u6d41\u7a0b.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"962\" height=\"623\" data-original=\"https:\/\/www.garfield-blog.top\/wp-content\/uploads\/2025\/10\/socket\u8fde\u63a5\u6d41\u7a0b.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-276\"  sizes=\"auto, (max-width: 962px) 100vw, 962px\" \/><\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u5173\u952e\u63a5\u53e3<\/h2>\n\n\n\n<p><code>socket<\/code>\u4f7f\u7528\u65f6\u6709\u51e0\u4e2a\u5e38\u7528\u7684\u63a5\u53e3<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">socket\u51fd\u6570<\/h3>\n\n\n\n<p><code>socket()<\/code>\u51fd\u6570\u7684\u539f\u578b\u5982\u4e0b\uff0c\u8fd9\u4e2a\u51fd\u6570\u5efa\u7acb\u4e00\u4e2a\u534f\u8bae\u65cf\u4e3a<code>domain<\/code>\u3001\u534f\u8bae\u7c7b\u578b\u4e3a<code>type<\/code>\u3001\u534f\u8bae\u7f16\u53f7\u4e3a<code>protocol<\/code>\u7684\u5957\u63a5\u5b57\u6587\u4ef6\u63cf\u8ff0\u7b26\u3002\u5982\u679c\u51fd\u6570\u8c03\u7528\u6210\u529f\uff0c\u4f1a\u8fd4\u56de\u4e00\u4e2a\u6807\u8bc6\u8fd9\u4e2a\u5957\u63a5\u5b57\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u5931\u8d25\u7684\u65f6\u5019\u8fd4\u56de<code>-1<\/code><\/p>\n\n\n\n<p><strong>\u51fd\u6570\u539f\u578b<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#include &lt;sys\/types.h&gt;<br> <br>#include &lt;sys\/socket.h&gt;<br> <br>int socket(int domain, int type, int protocol);<\/pre>\n\n\n\n<p><strong>domain\u53c2\u6570<\/strong> \u51fd\u6570<code>socket()<\/code>\u7684\u53c2\u6570<code>domain<\/code>\u7528\u4e8e\u8bbe\u7f6e\u7f51\u7edc\u901a\u4fe1\u7684\u57df\uff0c\u51fd\u6570<code>socket()<\/code>\u6839\u636e\u8fd9\u4e2a\u53c2\u6570\u9009\u62e9\u901a\u4fe1\u534f\u8bae\u7684\u65cf\u3002\u901a\u4fe1\u534f\u8bae\u65cf\u5728\u6587\u4ef6<code>sys\/socket.h<\/code>\u4e2d\u5b9a\u4e49\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u540d\u79f0<\/th><th>\u542b\u4e49<\/th><th>\u540d\u79f0<\/th><th>\u542b\u4e49<\/th><\/tr><\/thead><tbody><tr><td><code>PF_UNIX<\/code>,<code>PF_LOCAL<\/code><\/td><td>\u672c\u5730\u901a\u4fe1<\/td><td><code>PF_X25<\/code><\/td><td><code>ITU-T X25 \/ ISO-8208<\/code>\u534f\u8bae<\/td><\/tr><tr><td><code>AF_INET<\/code>,<code>PF_INET<\/code><\/td><td><code>IPv4 Internet<\/code>\u534f\u8bae<\/td><td><code>PF_AX25<\/code><\/td><td><code>Amateur radio AX.25<\/code><\/td><\/tr><tr><td><code>PF_INET6<\/code><\/td><td><code>IPv6 Internet<\/code>\u534f\u8bae<\/td><td><code>PF_ATMPVC<\/code><\/td><td>\u539f\u59cb<code>ATM PVC<\/code>\u8bbf\u95ee<\/td><\/tr><tr><td><code>PF_IPX<\/code><\/td><td><code>IPX-Novell<\/code>\u534f\u8bae<\/td><td><code>PF_APPLETALK<\/code><\/td><td><code>Appletalk<\/code><\/td><\/tr><tr><td><code>PF_NETLINK<\/code><\/td><td>\u5185\u6838\u7528\u6237\u754c\u9762\u8bbe\u5907<\/td><td><code>PF_PACKET<\/code><\/td><td>\u5e95\u5c42\u5305\u8bbf\u95ee<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>type\u53c2\u6570<\/strong> \u51fd\u6570socket()<code>\u7684\u53c2\u6570<\/code>type<code>\u7528\u4e8e\u8bbe\u7f6e\u5957\u63a5\u5b57\u901a\u4fe1\u7684\u7c7b\u578b\uff0c\u4e3b\u8981\u6709<\/code>SOCKET_STREAM<code>\uff08\u6d41\u5f0f\u5957\u63a5\u5b57\uff09\u3001<\/code>SOCK\u2014\u2014DGRAM`\uff08\u6570\u636e\u5305\u5957\u63a5\u5b57\uff09\u7b49<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u540d\u79f0<\/th><th>\u542b\u4e49<\/th><\/tr><\/thead><tbody><tr><td><code>SOCK_STREAM<\/code><\/td><td><code>TCP<\/code>\u8fde\u63a5\uff0c\u63d0\u4f9b\u5e8f\u5217\u5316\u7684\u3001\u53ef\u9760\u7684\u3001\u53cc\u5411\u8fde\u63a5\u7684\u5b57\u8282\u6d41\u3002\u652f\u6301\u5e26\u5916\u6570\u636e\u4f20\u8f93<\/td><\/tr><tr><td><code>SOCK_DGRAM<\/code><\/td><td>\u652f\u6301<code>UDP<\/code>\u8fde\u63a5\uff08\u65e0\u8fde\u63a5\u72b6\u6001\u7684\u6d88\u606f\uff09<\/td><\/tr><tr><td><code>SOCK_SEQPACKET<\/code><\/td><td>\u5e8f\u5217\u5316\u5305\uff0c\u63d0\u4f9b\u4e00\u4e2a\u5e8f\u5217\u5316\u7684\u3001\u53ef\u9760\u7684\u3001\u53cc\u5411\u7684\u57fa\u672c\u8fde\u63a5\u7684\u6570\u636e\u4f20\u8f93\u901a\u9053\uff0c\u6570\u636e\u957f\u5ea6\u5b9a\u5e38\u3002\u6bcf\u6b21\u8c03\u7528\u8bfb\u7cfb\u7edf\u8c03\u7528\u65f6\u6570\u636e\u9700\u8981\u5c06\u5168\u90e8\u6570\u636e\u8bfb\u51fa<\/td><\/tr><tr><td><code>SOCK_RAW<\/code><\/td><td><code>RAW<\/code>\u7c7b\u578b\uff0c\u63d0\u4f9b\u539f\u59cb\u7f51\u7edc\u534f\u8bae\u8bbf\u95ee<\/td><\/tr><tr><td><code>SOCK_RDM<\/code><\/td><td>\u63d0\u4f9b\u53ef\u9760\u7684\u6570\u636e\u62a5\u6587\uff0c\u4e0d\u8fc7\u53ef\u80fd\u6570\u636e\u4f1a\u6709\u4e71\u5e8f<\/td><\/tr><tr><td><code>SOCK_PACKET<\/code><\/td><td>\u8fd9\u662f\u4e00\u4e2a\u4e13\u7528\u7c7b\u578b\uff0c\u4e0d\u80fd\u5462\u8fc7\u5728\u901a\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5e76\u4e0d\u662f\u6240\u6709\u7684\u534f\u8bae\u65cf\u90fd\u5b9e\u73b0\u4e86\u8fd9\u4e9b\u534f\u8bae\u7c7b\u578b\uff0c\u4f8b\u5982\uff0c<code>AF_INET<\/code>\u534f\u8bae\u65cf\u5c31\u6ca1\u6709\u5b9e\u73b0<code>SOCK_SEQPACKET<\/code>\u534f\u8bae\u7c7b\u578b<\/p>\n\n\n\n<p><strong><code>protocol<\/code>\u53c2\u6570<\/strong> \u51fd\u6570<code>socket()<\/code>\u7684\u7b2c3\u4e2a\u53c2\u6570<code>protocol<\/code>\u7528\u4e8e\u5236\u5b9a\u67d0\u4e2a\u534f\u8bae\u7684\u7279\u5b9a\u7c7b\u578b\uff0c\u5373<code>type<\/code>\u7c7b\u578b\u4e2d\u7684\u67d0\u4e2a\u7c7b\u578b\u3002\u901a\u5e38\u67d0\u534f\u8bae\u4e2d\u53ea\u6709\u4e00\u79cd\u7279\u5b9a\u7c7b\u578b\uff0c\u8fd9\u6837<code>protocol<\/code>\u53c2\u6570\u4ec5\u80fd\u8bbe\u7f6e\u4e3a<code>0<\/code>\uff1b\u4f46\u662f\u6709\u4e9b\u534f\u8bae\u6709\u591a\u79cd\u7279\u5b9a\u7684\u7c7b\u578b\uff0c\u5c31\u9700\u8981\u8bbe\u7f6e\u8fd9\u4e2a\u53c2\u6570\u6765\u9009\u62e9\u7279\u5b9a\u7684\u7c7b\u578b<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7c7b\u578b\u4e3a<code>SOCK_STREAM<\/code>\u7684\u5957\u63a5\u5b57\u8868\u793a\u4e00\u4e2a\u53cc\u5411\u7684\u5b57\u8282\u6d41\uff0c\u4e0e\u7ba1\u9053\u7c7b\u4f3c\u3002\u6d41\u5f0f\u7684\u5957\u63a5\u5b57\u5728\u8fdb\u884c\u6570\u636e\u6536\u53d1\u4e4b\u524d\u5fc5\u987b\u5df2\u7ecf\u8fde\u63a5\uff0c\u8fde\u63a5\u4f7f\u7528<code>connect()<\/code>\u51fd\u6570\u8fdb\u884c\u3002\u4e00\u65e6\u8fde\u63a5\uff0c\u53ef\u4ee5\u4f7f\u7528<code>read()<\/code>\u6216\u8005<code>write()<\/code>\u51fd\u6570\u8fdb\u884c\u6570\u636e\u7684\u4f20\u8f93\u3002\u6d41\u5f0f\u901a\u4fe1\u65b9\u5f0f\u4fdd\u8bc1\u6570\u636e\u4e0d\u4f1a\u4e22\u5931\u6216\u8005\u91cd\u590d\u63a5\u6536\uff0c\u5f53\u6570\u636e\u5728\u4e00\u6bb5\u65f6\u95f4\u5185\u4efb\u7136\u6ca1\u6709\u63a5\u53d7\u5b8c\u6bd5\uff0c\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u8fde\u63a5\u4eba\u4e3a\u5df2\u7ecf\u6b7b\u6389<\/li>\n\n\n\n<li><code>SOCK_DGRAM<\/code>\u548c<code>SOCK_RAW<\/code> \u8fd9\u4e2a\u4e24\u79cd\u5957\u63a5\u5b57\u53ef\u4ee5\u4f7f\u7528\u51fd\u6570<code>sendto()<\/code>\u6765\u53d1\u9001\u6570\u636e\uff0c\u4f7f\u7528<code>recvfrom()<\/code>\u51fd\u6570\u63a5\u53d7\u6570\u636e\uff0c<code>recvfrom()<\/code>\u63a5\u53d7\u6765\u81ea\u5236\u5b9a<code>IP<\/code>\u5730\u5740\u7684\u53d1\u9001\u65b9\u7684\u6570\u636e<\/li>\n\n\n\n<li><code>SOCK_PACKET<\/code>\u662f\u4e00\u79cd\u4e13\u7528\u7684\u6570\u636e\u5305\uff0c\u5b83\u76f4\u63a5\u4ece\u8bbe\u5907\u9a71\u52a8\u63a5\u53d7\u6570\u636e<\/li>\n<\/ul>\n\n\n\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n\n\n\n<p>\u5efa\u7acb\u4e00\u4e2a\u6d41\u5f0f\u5957\u63a5\u5b57\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">int sock = socket(AF_INET, SOCK_STREAM, 0);<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">bind\u51fd\u6570<\/h3>\n\n\n\n<p><code>bind<\/code>\u51fd\u6570\u7684\u4f5c\u7528\u662f\u901a\u8fc7\u7ed1\u5b9a\u4e00\u4e2a\u5176\u4ed6<code>func<\/code>\u51fd\u6570\u751f\u6210\u4e00\u4e2a\u4f9d\u8d56\u4e8e<code>func<\/code>\u7684\u65b0\u7684\u51fd\u6570\u5bf9\u8c61\uff0c\u590d\u7528<code>func<\/code>\u51fd\u6570\u7684\u5b9e\u73b0\uff0c\u4f46\u662f\u53ef\u4ee5\u6539\u53d8\u8fd9\u4e2a<code>func<\/code>\u7684\u53c2\u6570\u6570\u91cf\u548c\u987a\u5e8f\uff0c\u53ef\u4ee5\u7ed1\u5b9a\u666e\u901a\u51fd\u6570\u3001\u5168\u5c40\u51fd\u6570\uff0c\u9759\u6001\u51fd\u6570\uff0c\u6210\u5458\u51fd\u6570\uff0c\u800c\u4e14\u5176\u53c2\u6570\u53ef\u4ee5\u652f\u6301\u5360\u4f4d\u7b26\uff08std::placeholders::<em>1\uff0cstd::placeholders::<\/em>2\uff09\u6765\u6539\u53d8\u53c2\u6570\u7684\u987a\u5e8f\uff0c\u5e76\u4e14\u53ef\u4ee5\u8bbe\u7f6e<code>func<\/code>\u4e2d\u9ed8\u8ba4\u7684\u51e0\u4e2a\u53c2\u6570\u6765\u51cf\u5c11\u8f93\u5165\u53c2\u6570\u7684\u6570\u91cf\u3002<\/p>\n\n\n\n<p><strong>\u51fd\u6570\u539f\u578b<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">int bind(int sockfd, const struct sockaddr *addr,socklen_t addrlen);<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>sockfd<\/code>\uff1a\u5957\u63a5\u5b57\u63cf\u8ff0\u7b26\uff0c\u662f\u901a\u8fc7 <code>socket()<\/code> \u521b\u5efa\u7684\u5957\u63a5\u5b57\u3002\u8fd9\u4e2a\u5957\u63a5\u5b57\u5c06\u88ab\u7ed1\u5b9a\u5230\u670d\u52a1\u7aef\u7684\u5730\u5740\u548c\u7aef\u53e3\n<ul class=\"wp-block-list\">\n<li>\u8fd9\u91cc\u7684 <code>addr<\/code> \u662f\u672c\u5730\u5730\u5740\uff08\u672c\u5730IP\u548c\u7aef\u53e3\uff09\uff0c\u5c06 <code>socket<\/code> \u7ed1\u5b9a\u5230\u672c\u5730\u7684\u67d0\u4e2a <code>IP<\/code> \u5730\u5740\u548c\u7aef\u53e3\u53f7<\/li>\n\n\n\n<li><strong>\u7528\u4e8e\u670d\u52a1\u5668\u7aef\uff0c\u6307\u5b9a\u672c\u5730\u76d1\u542c\u7684\u5730\u5740\u548c\u7aef\u53e3<\/strong><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code>addr<\/code>\uff1a\u6307\u5411\u4e00\u4e2a <code>struct sockaddr<\/code> \u7ed3\u6784\u4f53\u7684\u6307\u9488\uff0c\u5305\u542b\u4e86\u5957\u63a5\u5b57\u8981\u7ed1\u5b9a\u5230\u7684\u5730\u5740\u4fe1\u606f\u3002\u5bf9\u4e8e <code>IPv4<\/code>\uff0c\u901a\u5e38\u662f\u4e00\u4e2a <code>struct sockaddr_in<\/code> \u7ed3\u6784\u4f53<\/li>\n\n\n\n<li><code>addrlen<\/code>\uff1a\u5730\u5740\u7ed3\u6784\u7684\u5927\u5c0f\uff0c\u901a\u5e38\u4f7f\u7528 <code>sizeof(struct sockaddr_in)<\/code> \u6765\u8868\u793a<\/li>\n<\/ul>\n\n\n\n<p><strong>\u8fd4\u56de\u503c<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6210\u529f<\/strong>\uff1a\u8fd4\u56de <code>0<\/code>\uff0c\u8868\u793a\u7ed1\u5b9a\u6210\u529f<\/li>\n\n\n\n<li><strong>\u5931\u8d25<\/strong>\uff1a\u8fd4\u56de <code>-1<\/code>\uff0c\u5e76\u8bbe\u7f6e <code>errno<\/code> \u6765\u6307\u793a\u9519\u8bef\u539f\u56e0<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">listen\u51fd\u6570<\/h3>\n\n\n\n<p><code>listen<\/code>\u51fd\u6570\u7684\u4f5c\u7528\u662f\u5c06\u4e00\u4e2a\u5957\u63a5\u5b57\u6807\u8bb0\u4e3a\u76d1\u542c\u72b6\u6001\uff0c\u51c6\u5907\u63a5\u53d7\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u8bf7\u6c42\u3002\u5b83\u901a\u5e38\u5728\u521b\u5efa\u5e76\u7ed1\u5b9a\u4e00\u4e2a\u670d\u52a1\u5668\u7aef\u5957\u63a5\u5b57\u540e\u4f7f\u7528\uff0c\u8868\u793a\u670d\u52a1\u5668\u613f\u610f\u63a5\u53d7\u6765\u81ea\u5ba2\u6237\u7aef\u7684\u8fde\u63a5<\/p>\n\n\n\n<p><strong>\u51fd\u6570\u539f\u578b<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">int listen(int sockfd, int backlog);<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>sockfd<\/code>\uff1a\u8fd9\u662f\u4e00\u4e2a\u5957\u63a5\u5b57\u63cf\u8ff0\u7b26\uff0c\u901a\u5e38\u662f\u901a\u8fc7 <code>socket()<\/code> \u51fd\u6570\u521b\u5efa\u7684<\/li>\n\n\n\n<li><code>backlog<\/code>\uff1a\u8fd9\u662f\u4e00\u4e2a\u6574\u6570\uff0c\u6307\u5b9a\u8fde\u63a5\u8bf7\u6c42\u961f\u5217\u7684\u6700\u5927\u957f\u5ea6\u3002\u5373\uff0c\u5f53\u5ba2\u6237\u7aef\u8fde\u63a5\u8bf7\u6c42\u5230\u6765\u65f6\uff0c\u7cfb\u7edf\u4f1a\u5c06\u8fd9\u4e9b\u8fde\u63a5\u6392\u961f\uff0c\u76f4\u5230 <code>accept()<\/code> \u51fd\u6570\u63a5\u53d7\u8fde\u63a5\u3002\u5982\u679c\u961f\u5217\u5df2\u6ee1\uff0c\u65b0\u7684\u8fde\u63a5\u53ef\u80fd\u4f1a\u88ab\u62d2\u7edd<\/li>\n<\/ul>\n\n\n\n<p><strong>\u8fd4\u56de\u503c<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6210\u529f<\/strong>\uff1a\u8fd4\u56de <code>0<\/code> \u8868\u793a<\/li>\n\n\n\n<li><strong>\u5931\u8d25<\/strong>\uff1a\u8fd4\u56de <code>-1<\/code> \u8868\u793a\u51fa\u9519\uff0c\u5e76\u4e14\u8bbe\u7f6e\u4e86 <code>errno<\/code> \u4ee5\u6307\u793a\u9519\u8bef\u539f\u56e0<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">accept\u51fd\u6570<\/h3>\n\n\n\n<p><code>accept<\/code>\u51fd\u6570\u662f\u7528\u4e8e\u5728\u5957\u63a5\u5b57\u4e0a\u63a5\u53d7\u4f20\u5165\u8fde\u63a5\u7684\u51fd\u6570\u3002\u5b83\u901a\u5e38\u7528\u4e8e\u670d\u52a1\u5668\u7aef\uff0c\u4ee5\u5904\u7406\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u8bf7\u6c42<\/p>\n\n\n\n<p><strong>\u51fd\u6570\u539f\u578b<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#include &lt;sys\/types.h&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/* See NOTES *\/<br>#include &lt;sys\/socket.h&gt;<br>int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>sockfd<\/code>\uff1a\u670d\u52a1\u5668\u7aef\u7684\u5957\u63a5\u5b57\u63cf\u8ff0\u7b26\uff0c\u901a\u5e38\u662f\u901a\u8fc7 <code>socket()<\/code> \u51fd\u6570\u521b\u5efa\u5e76\u4e14\u901a\u8fc7 <code>bind()<\/code> \u7ed1\u5b9a\u540e\uff0c\u518d\u901a\u8fc7 <code>listen()<\/code> \u8bbe\u7f6e\u4e3a\u76d1\u542c\u72b6\u6001\u7684\u5957\u63a5\u5b57<\/li>\n\n\n\n<li><code>addr<\/code>\uff1a\u6307\u5411\u4e00\u4e2a <code>struct sockaddr<\/code> \u7ed3\u6784\u4f53\u7684\u6307\u9488\uff0c\u7528\u6765\u5b58\u50a8\u5ba2\u6237\u7aef\u7684\u5730\u5740\u4fe1\u606f\uff08\u4f8b\u5982\uff0cIP \u5730\u5740\u548c\u7aef\u53e3\u53f7\uff09\u3002\u53ef\u4ee5\u8bbe\u7f6e\u4e3a <code>NULL<\/code>\uff0c\u5982\u679c\u4e0d\u5173\u5fc3\u5ba2\u6237\u7aef\u5730\u5740\u4fe1\u606f<\/li>\n\n\n\n<li><code>addrlen<\/code>\uff1a\u6307\u5411\u4e00\u4e2a\u53d8\u91cf\uff0c\u8868\u793a <code>addr<\/code> \u7f13\u5b58\u533a\u7684\u957f\u5ea6\uff0c<code>accept()<\/code> \u8c03\u7528\u540e\uff0c\u8fd9\u4e2a\u53d8\u91cf\u4f1a\u88ab\u66f4\u65b0\u4e3a\u5ba2\u6237\u7aef\u5730\u5740\u7684\u5b9e\u9645\u957f\u5ea6<\/li>\n<\/ul>\n\n\n\n<p><strong>\u8fd4\u56de\u503c<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6210\u529f<\/strong>\uff1a<code>accept()<\/code> \u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u5957\u63a5\u5b57\u63cf\u8ff0\u7b26\uff0c\u8868\u793a\u4e0e\u5ba2\u6237\u7aef\u7684\u8fde\u63a5<\/li>\n\n\n\n<li><strong>\u5931\u8d25<\/strong>\uff1a\u8fd4\u56de <code>-1<\/code>\uff0c\u5e76\u8bbe\u7f6e <code>errno<\/code> \u6765\u6307\u793a\u9519\u8bef\u539f\u56e0<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">connect\u51fd\u6570<\/h3>\n\n\n\n<p><code>connect<\/code>\u51fd\u6570\u7684\u529f\u80fd\u53ef\u4ee5\u7528\u4e00\u53e5\u8bdd\u6765\u6982\u62ec\uff0c\u5c31\u662f\u5b8c\u6210\u9762\u5411\u8fde\u63a5\u7684\u534f\u8bae\u7684\u8fde\u63a5\u8fc7\u7a0b\uff0c\u5b83\u662f\u4e3b\u8981\u8fde\u63a5\u7684\u3002\u9762\u5411\u8fde\u63a5\u7684\u534f\u8bae\uff0c\u5728\u5efa\u7acb\u8fde\u63a5\u7684\u65f6\u5019\u603b\u4f1a\u6709\u4e00\u65b9\u5148\u53d1\u9001\u6570\u636e\uff0c\u90a3\u4e48\u8c01\u8c03\u7528\u4e86<code>connect<\/code>\u8c01\u5c31\u662f\u5148\u53d1\u9001\u6570\u636e\u7684\u4e00\u65b9<\/p>\n\n\n\n<p><strong>\u51fd\u6570\u539f\u578b<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#include &lt;sys\/types.h&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/* See NOTES *\/<br>#include &lt;sys\/socket.h&gt;<br>int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>sockfd<\/code>\uff1a\u5ba2\u6237\u7aef\u7684\u5957\u63a5\u5b57\u63cf\u8ff0\u7b26\uff0c\u901a\u5e38\u662f\u901a\u8fc7 <code>socket()<\/code> \u51fd\u6570\u521b\u5efa\u7684\n<ul class=\"wp-block-list\">\n<li>\u8fd9\u91cc\u7684 <code>addr<\/code> \u662f\u8fdc\u7a0b\u5730\u5740\uff08\u76ee\u6807\u670d\u52a1\u5668\u7684<code>IP<\/code>\u548c\u7aef\u53e3\uff09\uff0c\u5c06 <code>socket<\/code> \u8fde\u63a5\u5230\u8fdc\u7a0b\u4e3b\u673a\u7684\u6307\u5b9a\u5730\u5740\u548c\u7aef\u53e3<\/li>\n\n\n\n<li><strong>\u7528\u4e8e\u5ba2\u6237\u7aef\uff0c\u6307\u5b9a\u8981\u8fde\u63a5\u7684\u670d\u52a1\u5668\u5730\u5740\u548c\u7aef\u53e3<\/strong><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code>addr<\/code>\uff1a\u6307\u5411 <code>struct sockaddr<\/code> \u7ed3\u6784\u4f53\u7684\u6307\u9488\uff0c\u5305\u542b\u4e86\u76ee\u6807\u670d\u52a1\u5668\u7684\u5730\u5740\u4fe1\u606f\uff08<code>IP<\/code> \u5730\u5740\u548c\u7aef\u53e3\uff09<\/li>\n\n\n\n<li><code>addrlen<\/code>\uff1a\u5730\u5740\u7ed3\u6784\u7684\u5927\u5c0f\uff0c\u901a\u5e38\u53ef\u4ee5\u4f7f\u7528 <code>sizeof(struct sockaddr_in)<\/code><\/li>\n<\/ul>\n\n\n\n<p><strong>\u8fd4\u56de\u503c<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6210\u529f<\/strong>\uff1a\u8fd4\u56de <code>0<\/code> \u8868\u793a\u8fde\u63a5\u6210\u529f<\/li>\n\n\n\n<li><strong>\u5931\u8d25<\/strong>\uff1a\u8fd4\u56de <code>-1<\/code>\uff0c\u5e76\u8bbe\u7f6e <code>errno<\/code> \u4ee5\u6307\u793a\u9519\u8bef\u539f\u56e0<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">send\u51fd\u6570<\/h3>\n\n\n\n<p><code>send<\/code>\u51fd\u6570\u901a\u5e38\u7528\u4e8e \u5ba2\u6237\u7aef \u6216 \u670d\u52a1\u5668 \u5411\u5bf9\u65b9\u53d1\u9001\u6d88\u606f\u6216\u6570\u636e<\/p>\n\n\n\n<p><strong>\u51fd\u6570\u539f\u578b<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ssize_t send(int sockfd, const void *buf, size_t len, int flags);<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>sockfd<\/code>\uff1a\u5957\u63a5\u5b57\u63cf\u8ff0\u7b26\uff0c\u662f\u5df2\u5efa\u7acb\u8fde\u63a5\u7684\u5957\u63a5\u5b57\uff08\u4f8b\u5982\uff0c\u901a\u8fc7 <code>socket()<\/code> \u521b\u5efa\u5e76\u901a\u8fc7 <code>connect()<\/code> \u6216 <code>accept()<\/code> \u8fde\u63a5\u540e\u7684\u5957\u63a5\u5b57\uff09\u3002\u5b83\u6307\u5b9a\u4e86\u8981\u53d1\u9001\u6570\u636e\u7684\u76ee\u6807\u5957\u63a5\u5b57\u3002<\/li>\n\n\n\n<li><code>buf<\/code>\uff1a\u6307\u5411\u8981\u53d1\u9001\u7684\u6570\u636e\u7684\u7f13\u51b2\u533a\uff08\u5185\u5b58\u5730\u5740\uff09\u3002\u8fd9\u662f\u4e00\u4e2a\u6307\u5411 <code>char<\/code> \u7c7b\u578b\u6570\u636e\u7684\u6307\u9488\uff0c\u5b58\u50a8\u4e86\u9700\u8981\u53d1\u9001\u7684\u6d88\u606f\u6216\u6570\u636e<\/li>\n\n\n\n<li><code>len<\/code>\uff1a\u8981\u53d1\u9001\u7684\u6570\u636e\u7684\u5b57\u8282\u6570\uff0c\u901a\u5e38\u662f\u7f13\u51b2\u533a\u4e2d\u6570\u636e\u7684\u957f\u5ea6<\/li>\n\n\n\n<li><code>flags<\/code>\uff1a\u8bbe\u7f6e\u53d1\u9001\u884c\u4e3a\u7684\u6807\u5fd7\u4f4d\u3002\u5e38\u7528\u7684\u6807\u5fd7\u5305\u62ec\uff1a\n<ul class=\"wp-block-list\">\n<li><code>0<\/code>\uff1a\u8868\u793a\u6b63\u5e38\u53d1\u9001<\/li>\n\n\n\n<li><code>MSG_CONFIRM<\/code>\uff1a\u8bf7\u6c42\u786e\u8ba4\u6d88\u606f\u53d1\u9001<\/li>\n\n\n\n<li><code>MSG_DONTROUTE<\/code>\uff1a\u4e0d\u4f7f\u7528\u8def\u7531\u8868\u76f4\u63a5\u53d1\u9001\u6570\u636e\uff08\u7ed5\u8fc7\u8def\u7531\u5668\uff09<\/li>\n\n\n\n<li><code>MSG_NOSIGNAL<\/code>\uff1a\u9632\u6b62\u53d1\u9001 SIGPIPE \u4fe1\u53f7<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><strong>\u8fd4\u56de\u503c<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6210\u529f<\/strong>\uff1a\u8fd4\u56de\u53d1\u9001\u7684\u5b57\u8282\u6570\uff08\u5373\u6210\u529f\u53d1\u9001\u7684\u6570\u636e\u91cf\uff09\u3002\u8fd9\u4e2a\u503c\u53ef\u80fd\u5c0f\u4e8e <code>len<\/code>\uff0c\u56e0\u4e3a\u6570\u636e\u53ef\u80fd\u672a\u5b8c\u5168\u53d1\u9001\uff0c\u8fd9\u65f6\u5019\u9700\u8981\u518d\u6b21\u8c03\u7528 <code>send()<\/code> \u7ee7\u7eed\u53d1\u9001\u5269\u4f59\u7684\u6570\u636e<\/li>\n\n\n\n<li><strong>\u5931\u8d25<\/strong>\uff1a\u8fd4\u56de <code>-1<\/code>\uff0c\u5e76\u8bbe\u7f6e <code>errno<\/code> \u6765\u6307\u793a\u9519\u8bef\u539f\u56e0<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">recv\u51fd\u6570<\/h3>\n\n\n\n<p><code>recv()<\/code> \u51fd\u6570\u7528\u4e8e\u4ece\u5df2\u7ecf\u5efa\u7acb\u8fde\u63a5\u7684\u5957\u63a5\u5b57\u63a5\u6536\u6570\u636e\u3002\u5b83\u662f \u63a5\u6536\u6570\u636e \u7684\u6838\u5fc3\u51fd\u6570\uff0c\u901a\u5e38\u5728\u670d\u52a1\u5668\u7aef\u7528\u4e8e\u63a5\u6536\u5ba2\u6237\u7aef\u53d1\u9001\u7684\u6570\u636e\uff0c\u6216\u8005\u5728\u5ba2\u6237\u7aef\u63a5\u6536\u4ece\u670d\u52a1\u5668\u4f20\u6765\u7684\u54cd\u5e94\u6570\u636e<\/p>\n\n\n\n<p><strong>\u51fd\u6570\u539f\u578b<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ssize_t recv(int sockfd, void *buf, size_t len, int flags);<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>sockfd<\/code>\uff1a\u5df2\u8fde\u63a5\u7684\u5957\u63a5\u5b57\u63cf\u8ff0\u7b26\u3002\u8fd9\u4e2a\u5957\u63a5\u5b57\u662f\u901a\u8fc7 <code>socket()<\/code> \u521b\u5efa\u5e76\u901a\u8fc7 <code>connect()<\/code>\uff08\u5ba2\u6237\u7aef\uff09\u6216 <code>accept()<\/code>\uff08\u670d\u52a1\u5668\u7aef\uff09\u5efa\u7acb\u8fde\u63a5\u7684\u5957\u63a5\u5b57\u3002<\/li>\n\n\n\n<li><code>buf<\/code>\uff1a\u6307\u5411\u63a5\u6536\u6570\u636e\u7f13\u51b2\u533a\u7684\u6307\u9488\uff0c\u7528\u4e8e\u5b58\u50a8\u63a5\u6536\u5230\u7684\u6570\u636e<\/li>\n\n\n\n<li><code>len<\/code>\uff1a\u8981\u63a5\u6536\u7684\u6700\u5927\u5b57\u8282\u6570\u3002<code>recv()<\/code> \u51fd\u6570\u4f1a\u5c06\u6700\u591a <code>len<\/code> \u5b57\u8282\u7684\u6570\u636e\u5b58\u5165 <code>buf<\/code> \u4e2d<\/li>\n\n\n\n<li><code>flags<\/code>\uff1a\u6307\u5b9a\u63a5\u6536\u64cd\u4f5c\u7684\u884c\u4e3a\u6807\u5fd7\u3002\u5e38\u7528\u7684\u6807\u5fd7\u6709\uff1a\n<ul class=\"wp-block-list\">\n<li><code>0<\/code>\uff1a\u9ed8\u8ba4\u884c\u4e3a\uff0c\u6b63\u5e38\u63a5\u6536<\/li>\n\n\n\n<li><code>MSG_PEEK<\/code>\uff1a\u67e5\u770b\u7f13\u51b2\u533a\u7684\u6570\u636e\u800c\u4e0d\u5c06\u5176\u4ece\u7f13\u51b2\u533a\u4e2d\u79fb\u9664<\/li>\n\n\n\n<li><code>MSG_WAITALL<\/code>\uff1a\u8981\u6c42 <code>recv()<\/code> \u7b49\u5230 <code>len<\/code> \u5b57\u8282\u7684\u6570\u636e\u90fd\u88ab\u63a5\u6536\u5230\uff08\u5bf9\u4e8e\u6d41\u5957\u63a5\u5b57\uff0c\u53ef\u80fd\u9700\u8981\u591a\u6b21\u8c03\u7528\u624d\u80fd\u5b8c\u5168\u63a5\u6536 <code>len<\/code> \u5b57\u8282\uff09<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><strong>\u8fd4\u56de\u503c<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6210\u529f<\/strong>\uff1a\u8fd4\u56de\u5b9e\u9645\u63a5\u6536\u7684\u5b57\u8282\u6570\uff08\u53ef\u4ee5\u5c0f\u4e8e\u8bf7\u6c42\u7684 <code>len<\/code>\uff0c\u7279\u522b\u662f\u5728\u6d41\u5957\u63a5\u5b57\uff08\u5982 TCP\uff09\u4e2d\uff09\u3002\u5982\u679c\u8fd4\u56de 0\uff0c\u8868\u793a\u8fde\u63a5\u5df2\u5173\u95ed<\/li>\n\n\n\n<li><strong>\u5931\u8d25<\/strong>\uff1a\u8fd4\u56de <code>-1<\/code>\uff0c\u5e76\u8bbe\u7f6e <code>errno<\/code> \u6765\u6307\u793a\u9519\u8bef\u539f\u56e0<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">close\u51fd\u6570&amp;shutdown\u51fd\u6570<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">close\u51fd\u6570<\/h4>\n\n\n\n<p><code>close<\/code> \u4e00\u4e2a\u5957\u63a5\u5b57\u7684\u9ed8\u8ba4\u884c\u4e3a\u662f\u628a\u5957\u63a5\u5b57\u6807\u8bb0\u4e3a\u5df2\u5173\u95ed\uff0c\u7136\u540e\u7acb\u5373\u8fd4\u56de\u5230\u8c03\u7528\u8fdb\u7a0b<\/p>\n\n\n\n<p><strong>\u51fd\u6570\u539f\u578b<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">int close(int sockfd); &nbsp; &nbsp; \/\/\u8fd4\u56de\u6210\u529f\u4e3a0\uff0c\u51fa\u9519\u4e3a-1.<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">shutdown\u51fd\u6570<\/h4>\n\n\n\n<p><strong>\u51fd\u6570\u539f\u578b<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">int shutdown(int sockfd,int howto); &nbsp;\/\/\u8fd4\u56de\u6210\u529f\u4e3a0\uff0c\u51fa\u9519\u4e3a-1<\/pre>\n\n\n\n<p>\u8be5\u51fd\u6570\u7684\u884c\u4e3a\u4f9d\u8d56\u4e8e<code>howto<\/code>\u7684\u503c<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>SHUT_RD<\/code>\uff1a\u503c\u4e3a<code>0<\/code>\uff0c\u5173\u95ed\u8fde\u63a5\u7684\u8bfb\u8fd9\u4e00\u534a<\/li>\n\n\n\n<li><code>SHUT_WR<\/code>\uff1a\u503c\u4e3a<code>1<\/code>\uff0c\u5173\u95ed\u8fde\u63a5\u7684\u5199\u8fd9\u4e00\u534a<\/li>\n\n\n\n<li><code>SHUT_RDWR<\/code>\uff1a\u503c\u4e3a<code>2<\/code>\uff0c\u8fde\u63a5\u7684\u8bfb\u548c\u5199\u90fd\u5173\u95ed<\/li>\n<\/ul>\n\n\n\n<p><strong>\u4e24\u51fd\u6570\u7684\u533a\u522b<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>close<\/code>\u51fd\u6570\u4f1a\u5173\u95ed\u5957\u63a5\u5b57<code>ID<\/code>\uff0c\u5982\u679c\u6709\u5176\u4ed6\u7684\u8fdb\u7a0b\u5171\u4eab\u7740\u8fd9\u4e2a\u5957\u63a5\u5b57\uff0c\u90a3\u4e48\u5b83\u4ecd\u7136\u662f\u6253\u5f00\u7684\uff0c\u8fd9\u4e2a\u8fde\u63a5\u4ecd\u7136\u53ef\u4ee5\u7528\u6765\u8bfb\u548c\u5199\uff0c\u5e76\u4e14\u6709\u65f6\u5019\u8fd9\u662f\u975e\u5e38\u91cd\u8981\u7684 \uff0c\u7279\u522b\u662f\u5bf9\u4e8e\u591a\u8fdb\u7a0b\u5e76\u53d1\u670d\u52a1\u5668\u6765\u8bf4<\/li>\n\n\n\n<li><code>shutdown<\/code>\u4f1a\u5207\u65ad\u8fdb\u7a0b\u5171\u4eab\u7684\u5957\u63a5\u5b57\u7684\u6240\u6709\u8fde\u63a5\uff0c\u4e0d\u7ba1\u8fd9\u4e2a\u5957\u63a5\u5b57\u7684\u5f15\u7528\u8ba1\u6570\u662f\u5426\u4e3a\u96f6\uff0c\u90a3\u4e9b\u8bd5\u56fe\u8bfb\u5f97\u8fdb\u7a0b\u5c06\u4f1a\u63a5\u6536\u5230<code>EOF<\/code>\u6807\u8bc6\uff0c\u90a3\u4e9b\u8bd5\u56fe\u5199\u7684\u8fdb\u7a0b\u5c06\u4f1a\u68c0\u6d4b\u5230<code>SIGPIPE<\/code>\u4fe1\u53f7\uff0c\u540c\u65f6\u53ef\u5229\u7528<code>shutdown<\/code>\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u9009\u62e9\u65ad\u8fde\u7684\u65b9\u5f0f<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Socket\u8fde\u63a5\u6d41\u7a0b \u53c2\u8003\u6587\u6863 Socket\u5230\u5e95\u662f\u4ec0\u4e48\uff1f\u4f60\u60f3\u77e5\u9053\u5417\uff1f-socket\u662f\u4ec0\u4e48\u610f\u601d (51cto.c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[10],"tags":[],"class_list":["post-184","post","type-post","status-publish","format-standard","hentry","category-10"],"_links":{"self":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts\/184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=184"}],"version-history":[{"count":3,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts\/184\/revisions"}],"predecessor-version":[{"id":277,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts\/184\/revisions\/277"}],"wp:attachment":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}