{"id":776,"date":"2024-11-07T11:55:25","date_gmt":"2024-11-07T03:55:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/776\/"},"modified":"2024-11-07T11:55:25","modified_gmt":"2024-11-07T03:55:25","slug":"c%e8%af%ad%e8%a8%80%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b%ef%bc%9a%e5%b8%b8%e8%a7%81%e9%94%99%e8%af%af%e5%8f%8a%e5%85%b6%e4%bf%ae%e5%a4%8d%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/776\/","title":{"rendered":"C\u8bed\u8a00\u7f51\u7edc\u7f16\u7a0b\uff1a\u5e38\u89c1\u9519\u8bef\u53ca\u5176\u4fee\u590d\u65b9\u6cd5"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1130\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172854036269518.jpg\" width=\"720\" height=\"288\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172854036269518.jpg 720w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172854036269518-300x120.jpg 300w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172854036269518-670x268.jpg 670w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" title=\"C\u8bed\u8a00\u7f51\u7edc\u7f16\u7a0b\uff1a\u5e38\u89c1\u9519\u8bef\u53ca\u5176\u4fee\u590d\u65b9\u6cd5\u63d2\u56fe\" alt=\"C\u8bed\u8a00\u7f51\u7edc\u7f16\u7a0b\uff1a\u5e38\u89c1\u9519\u8bef\u53ca\u5176\u4fee\u590d\u65b9\u6cd5\u63d2\u56fe\" \/><\/p>\n<p><strong>C \u8bed\u8a00\u7f51\u7edc\u7f16\u7a0b\uff1a\u5e38\u89c1\u9519\u8bef\u53ca\u5176\u4fee\u590d\u65b9\u6cd5<\/strong><\/p>\n<p><strong>1. \u8fde\u63a5\u91cd\u7f6e<\/strong><\/p>\n<p>\u9519\u8bef\uff1aerrno \u8fd4\u56de ECONNRESET\u3002<\/p>\n<p>\u539f\u56e0\uff1a\u5bf9\u7aef\u7a81\u7136\u7ec8\u6b62\u8fde\u63a5\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201cC\u8bed\u8a00\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09\u201d\uff1b<\/p>\n<p>\u4fee\u590d\uff1a<\/p>\n<ul>\n<li>\u68c0\u67e5\u670d\u52a1\u5668\u7aef\u662f\u5426\u6b63\u786e\u5173\u95ed\u8fde\u63a5\u3002<\/li>\n<li>\u9002\u5f53\u914d\u7f6e\u9632\u706b\u5899\u548c\u8def\u7531\u5668\u3002<\/li>\n<\/ul>\n<p><strong>2. \u8fde\u63a5\u8d85\u65f6<\/strong><\/p>\n<p>\u9519\u8bef\uff1aerrno \u8fd4\u56de ETIMEDOUT\u3002<\/p>\n<p>\u539f\u56e0\uff1a\u670d\u52a1\u5668\u5728\u6307\u5b9a\u65f6\u95f4\u5185\u672a\u54cd\u5e94\u3002<\/p>\n<p>\u4fee\u590d\uff1a<\/p>\n<ul>\n<li>\u589e\u52a0\u8fde\u63a5\u8d85\u65f6\u3002<\/li>\n<li>\u68c0\u67e5\u670d\u52a1\u5668\u7aef\u662f\u5426\u6b63\u5e38\u8fd0\u884c\u3002<\/li>\n<\/ul>\n<p><strong>3. \u5957\u63a5\u5b57\u65e0\u53ef\u7528\u7aef\u53e3<\/strong><\/p>\n<p>\u9519\u8bef\uff1aerrno \u8fd4\u56de EADDRNOTAVAIL\u3002<\/p>\n<p>\u539f\u56e0\uff1a\u5c1d\u8bd5\u7ed1\u5b9a\u4e0d\u5b58\u5728\u6216\u5df2\u5173\u95ed\u7684\u7aef\u53e3\u3002<\/p>\n<p>\u4fee\u590d\uff1a<\/p>\n<ul>\n<li>\u9009\u62e9\u4e00\u4e2a\u53ef\u7528\u7aef\u53e3\u3002<\/li>\n<li>\u786e\u4fdd\u670d\u52a1\u5668\u7aef\u6b63\u786e\u4fa6\u542c\u7aef\u53e3\u3002<\/li>\n<\/ul>\n<p><strong>4. \u5bfb\u5740\u4fe1\u606f\u4e0d\u6b63\u786e<\/strong><\/p>\n<p>\u9519\u8bef\uff1aerrno \u8fd4\u56de EAI_AGAIN\u3001EAI_FAIL \u6216 EAI_NONAME\u3002<\/p>\n<p>\u539f\u56e0\uff1a\u63d0\u4f9b\u7684 IP \u5730\u5740\u6216\u4e3b\u673a\u540d\u65e0\u6548\u3002<\/p>\n<p>\u4fee\u590d\uff1a<\/p>\n<ul>\n<li>\u9a8c\u8bc1 IP \u5730\u5740\u6216\u4e3b\u673a\u540d\u662f\u5426\u5b58\u5728\u3002<\/li>\n<li>\u68c0\u67e5 DNS \u8bbe\u7f6e\u662f\u5426\u6b63\u786e\u3002<\/li>\n<\/ul>\n<p><strong>\u4f8b\u5b50\uff1a<\/strong><\/p>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u6355\u83b7\u5e76\u5904\u7406 ECONNRESET \u9519\u8bef\uff1a<\/p>\n<pre>#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n#include &lt;errno.h&gt;\n\nint main() {\n    \/\/ \u4ee3\u7801\u7565...\n\n    int error = connect(socket, (struct sockaddr *)&amp;amp;server, sizeof(server));\n    if (error &lt;\/errno.h&gt;&lt;\/stdlib.h&gt;&lt;\/stdio.h&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fC\u8bed\u8a00\u7f51\u7edc\u7f16\u7a0b\uff1a\u5e38\u89c1\u9519\u8bef\u53ca\u5176\u4fee\u590d\u65b9\u6cd5\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C \u8bed\u8a00\u7f51\u7edc\u7f16\u7a0b\uff1a\u5e38\u89c1\u9519\u8bef\u53ca\u5176\u4fee\u590d\u65b9\u6cd5 1. \u8fde\u63a5\u91cd\u7f6e \u9519\u8bef\uff1aerrno \u8fd4\u56de ECONNRESET\u3002 \u539f\u56e0\uff1a\u5bf9\u7aef\u7a81\u7136\u7ec8\u6b62\u8fde\u63a5\u3002 \u7acb\u5373\u5b66\u4e60\u201cC\u8bed\u8a00\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09\u201d\uff1b \u4fee\u590d\uff1a \u68c0\u67e5\u670d\u52a1\u5668\u7aef\u662f\u5426\u6b63\u786e\u5173\u95ed\u8fde\u63a5\u3002 \u9002\u5f53\u914d\u7f6e\u9632\u706b\u5899\u548c\u8def\u7531\u5668\u3002 2. \u8fde\u63a5\u8d85\u65f6 \u9519\u8bef\uff1aerrno \u8fd4\u56de ETIMEDOUT\u3002 \u539f\u56e0\uff1a\u670d\u52a1\u5668\u5728\u6307\u5b9a\u65f6\u95f4\u5185\u672a\u54cd\u5e94\u3002 \u4fee\u590d\uff1a \u589e\u52a0\u8fde\u63a5\u8d85\u65f6\u3002 \u68c0\u67e5\u670d\u52a1\u5668\u7aef\u662f\u5426\u6b63\u5e38\u8fd0\u884c\u3002 3. \u5957\u63a5\u5b57\u65e0\u53ef\u7528\u7aef\u53e3 \u9519\u8bef\uff1aerrno \u8fd4\u56de EADDRNOTAVAIL\u3002 \u539f\u56e0\uff1a\u5c1d\u8bd5\u7ed1\u5b9a\u4e0d\u5b58\u5728\u6216\u5df2\u5173\u95ed\u7684\u7aef\u53e3\u3002 \u4fee\u590d\uff1a \u9009\u62e9\u4e00\u4e2a\u53ef\u7528\u7aef\u53e3\u3002 \u786e\u4fdd\u670d\u52a1\u5668\u7aef\u6b63\u786e\u4fa6\u542c\u7aef\u53e3\u3002 4. \u5bfb\u5740\u4fe1\u606f\u4e0d\u6b63\u786e \u9519\u8bef\uff1aerrno \u8fd4\u56de EAI_AGAIN\u3001EAI_FAIL \u6216 EAI_NONAME\u3002 \u539f\u56e0\uff1a\u63d0\u4f9b\u7684 IP \u5730\u5740\u6216\u4e3b\u673a\u540d\u65e0\u6548\u3002 \u4fee\u590d\uff1a \u9a8c\u8bc1 IP \u5730\u5740\u6216\u4e3b\u673a\u540d\u662f\u5426\u5b58\u5728\u3002 \u68c0\u67e5 DNS \u8bbe\u7f6e\u662f\u5426\u6b63\u786e\u3002 \u4f8b\u5b50\uff1a \u4ee5\u4e0b\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u6355\u83b7\u5e76\u5904\u7406 ECONNRESET \u9519\u8bef\uff1a #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-776","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/776","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=776"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/776\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=776"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=776"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=776"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}