{"id":119199,"date":"2026-10-29T03:08:27","date_gmt":"2026-10-28T19:08:27","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/119199.html"},"modified":"2026-10-29T03:08:27","modified_gmt":"2026-10-28T19:08:27","slug":"linux-%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0%ef%bc%88%e5%9b%9b%e5%8d%81%ef%bc%89%ef%bc%9atcp-%e7%bc%96%e7%a8%8b-%e4%bb%8e%e7%90%86%e8%ae%ba%e5%88%b0-echoserver-%e5%ae%9e%e6%88%98","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/119199.html","title":{"rendered":"Linux \u5b66\u4e60\u7b14\u8bb0\uff08\u56db\u5341\uff09\uff1aTCP \u7f16\u7a0b\u2014\u2014\u4ece\u7406\u8bba\u5230 EchoServer \u5b9e\u6218"},"content":{"rendered":"<h3>&#x1f4cc; \u6838\u5fc3\u7ed3\u8bba&#xff08;TL;DR&#xff09;&#xff1a;<\/h3>\n<li>\n<p>TCP \u6838\u5fc3\u7279\u6027&#xff1a;\u9762\u5411\u8fde\u63a5&#xff08;\u4e09\u6b21\u63e1\u624b&#xff09;\u3001\u53ef\u9760\u4f20\u8f93\u3001\u9762\u5411\u5b57\u8282\u6d41\u3002<\/p>\n<\/li>\n<li>\n<p>\u670d\u52a1\u7aef\u4e94\u6b65\u66f2&#xff1a;socket() -&gt; bind() -&gt; listen() -&gt; accept() -&gt; read()\/write()\u3002<\/p>\n<\/li>\n<li>\n<p>\u6781\u5176\u91cd\u8981&#xff1a;accept() \u6210\u529f\u540e\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u5168\u65b0\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26 connfd&#xff0c;\u4e13\u95e8\u7528\u4e8e\u548c\u8be5\u5ba2\u6237\u7aef\u901a\u4fe1&#xff0c;\u539f\u6765\u7684 listenfd \u7ee7\u7eed\u76d1\u542c\u3002<\/p>\n<\/li>\n<li>\n<p>\u65ad\u7ebf\u611f\u77e5&#xff1a;TCP \u4e2d read() \u8fd4\u56de 0&#xff0c;\u4ee3\u8868\u5bf9\u7aef&#xff08;\u5ba2\u6237\u7aef&#xff09;\u4e3b\u52a8\u5173\u95ed\u4e86\u8fde\u63a5&#xff0c;\u800c\u4e0d\u662f\u51fa\u9519\u3002<\/p>\n<\/li>\n<li>\n<p>\u8e29\u5751\u9632\u8303&#xff1a;\u670d\u52a1\u7aef\u91cd\u542f\u5e38\u9047 Address already in use&#xff0c;\u9700\u7528 setsockopt() \u8bbe\u7f6e SO_REUSEADDR \u7aef\u53e3\u590d\u7528\u3002<\/p>\n<\/li>\n<h3>\u4e00\u3001 TCP \u6838\u5fc3\u6d41\u7a0b\u89e3\u6790<\/h3>\n<p>TCP \u5c31\u50cf\u6253\u7535\u8bdd&#xff0c;\u5fc5\u987b\u5148\u5efa\u7acb\u8fde\u63a5\u3002<\/p>\n<ul>\n<li>\n<p>\u670d\u52a1\u5668\u7aef&#xff1a;socket\u521b\u5efa\u7535\u8bdd\u673a&#xff0c;bind\u63d2\u5361\u7ed1\u5b9a\u56fa\u5b9a\u53f7\u7801&#xff0c;listen\u5f00\u673a\u5f85\u673a&#xff0c;accept\u63a5\u542c\u3002<\/p>\n<\/li>\n<li>\n<p>\u5ba2\u6237\u7aef&#xff1a;socket\u521b\u5efa\u7535\u8bdd\u673a&#xff0c;connect\u76f4\u63a5\u62e8\u53f7\u3002<br \/>\n(\u6ce8&#xff1a;\u5ba2\u6237\u7aef\u4e0d\u9700\u8981\u624b\u52a8 bind&#xff0c;connect \u65f6\u64cd\u4f5c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u5206\u914d\u968f\u673a\u7aef\u53e3)<\/p>\n<\/li>\n<\/ul>\n<h3>\u4e8c\u3001 \u4e3a\u4ec0\u4e48 accept \u8981\u8fd4\u56de\u65b0\u7684\u5957\u63a5\u5b57&#xff1f;<\/h3>\n<p>listen_fd \u662f\u8d1f\u8d23\u76d1\u542c\u662f\u5426\u6709\u65b0\u8fde\u63a5\u8fdb\u6765\u7684&#xff08;\u53ea\u8d1f\u8d23\u62c9\u5ba2&#xff09;&#xff0c;\u800c accept \u8fd4\u56de\u7684 conn_fd \u624d\u662f\u771f\u6b63\u7528\u6765\u548c\u5f53\u524d\u5ba2\u6237\u7aef\u901a\u4fe1\u7684\u3002\u5982\u679c\u4e0d\u8fd9\u6837\u505a&#xff0c;\u670d\u52a1\u5668\u5c31\u65e0\u6cd5\u540c\u65f6\u4e3a\u591a\u4e2a\u5ba2\u6237\u7aef\u670d\u52a1\u3002<\/p>\n<h3>\u4e09\u3001 \u5b9e\u6218&#xff1a;\u5355\u8fdb\u7a0b TCP Echo \u670d\u52a1\u5668<\/h3>\n<p>(\u8fd9\u91cc\u53ea\u5c55\u793a\u6838\u5fc3\u903b\u8f91&#xff0c;\u5b8c\u6574\u4ee3\u7801\u89c1\u6587\u672b)<\/p>\n<p>\/\/ \u7aef\u53e3\u590d\u7528&#xff0c;\u89e3\u51b3\u91cd\u542f\u62a5\u9519\u95ee\u9898<br \/>\nint opt &#061; 1;<br \/>\nsetsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &amp;opt, sizeof(opt));<\/p>\n<p>\/\/ \u63a5\u6536\u8fde\u63a5<br \/>\nint conn_fd &#061; accept(listen_fd, (struct sockaddr*)&amp;client_addr, &amp;client_len);<\/p>\n<p>\/\/ \u901a\u4fe1\u4e0e\u65ad\u7ebf\u5224\u65ad<br \/>\nint n &#061; read(conn_fd, buffer, BUF_SIZE);<br \/>\nif (n &gt; 0) {<br \/>\n    \/\/ \u6b63\u5e38\u6536\u5230\u6570\u636e<br \/>\n    write(conn_fd, buffer, n);<br \/>\n} else if (n &#061;&#061; 0) {<br \/>\n    \/\/ \u91cd\u70b9&#xff1a;n &#061;&#061; 0 \u4ee3\u8868\u5ba2\u6237\u7aef\u5173\u95ed\u4e86\u8fde\u63a5 (\u6536\u5230\u4e86 FIN \u5305)<br \/>\n    printf(&#034;\u5ba2\u6237\u7aef\u5df2\u65ad\u5f00\u8fde\u63a5\u3002\\\\n&#034;);<br \/>\n    break;<br \/>\n}<\/p>\n<h3>\u56db\u3001 \u8e29\u5751\u8bb0\u5f55&#xff1a;Address already in use<\/h3>\n<ul>\n<li>\n<p>\u73b0\u8c61&#xff1a;\u5f3a\u5236 Ctrl&#043;C \u7ed3\u675f\u670d\u52a1\u5668\u540e&#xff0c;\u7acb\u523b\u91cd\u65b0\u8fd0\u884c&#xff0c;\u62a5\u9519 bind error: Address already in use\u3002<\/p>\n<\/li>\n<li>\n<p>\u539f\u56e0&#xff1a;TCP \u8fde\u63a5\u65ad\u5f00\u65f6&#xff0c;\u4e3b\u52a8\u65ad\u5f00\u65b9\u4f1a\u8fdb\u5165 TIME_WAIT \u72b6\u6001&#xff0c;\u5360\u7528\u7aef\u53e3\u4e00\u6bb5\u65f6\u95f4&#xff08;\u901a\u5e38\u662f 2MSL&#xff0c;\u7ea6 1 \u5206\u949f&#xff09;&#xff0c;\u9632\u6b62\u6700\u540e\u4e00\u4e2a ACK \u4e22\u5931\u5bfc\u81f4\u8fde\u63a5\u6df7\u4e71\u3002<\/p>\n<\/li>\n<li>\n<p>\u89e3\u51b3&#xff1a;\u5728 bind \u524d\u8c03\u7528 setsockopt \u8bbe\u7f6e SO_REUSEADDR&#xff0c;\u5141\u8bb8\u7aef\u53e3\u590d\u7528\u3002<\/p>\n<\/li>\n<\/ul>\n<h3>\u4e94\u3001 \u5c40\u9650\u6027<\/h3>\n<p>\u5f53\u524d\u7684\u670d\u52a1\u5668\u662f\u5355\u8fdb\u7a0b\u3001\u5355\u7ebf\u7a0b\u7684\u3002\u4e00\u65e6 accept \u6210\u529f&#xff0c;\u670d\u52a1\u5668\u5c31\u9677\u5165\u4e86 while(read) \u7684\u963b\u585e\u3002\u6b64\u65f6&#xff0c;\u7b2c\u4e8c\u4e2a\u5ba2\u6237\u7aef\u8fde\u90fd\u8fde\u4e0d\u8fdb\u6765\u3002<\/p>\n<h3>\u81ea\u6211\u5b9e\u6218\u64cd\u4f5c<\/h3>\n<p>cd ~\/linux_study\/network_test<\/p>\n<h5>\u670d\u52a1\u7aef tcp_server.c<\/h5>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include &lt;arpa\/inet.h&gt;<\/p>\n<p>#define PORT 9999<br \/>\n#define BUF_SIZE 1024<\/p>\n<p>int main() {<br \/>\n    int listen_fd &#061; socket(AF_INET, SOCK_STREAM, 0);<\/p>\n<p>    \/\/ \u7aef\u53e3\u590d\u7528&#xff0c;\u9632\u6b62\u91cd\u542f\u65f6 Address already in use<br \/>\n    int opt &#061; 1;<br \/>\n    setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &amp;opt, sizeof(opt));<\/p>\n<p>    struct sockaddr_in server_addr;<br \/>\n    memset(&amp;server_addr, 0, sizeof(server_addr));<br \/>\n    server_addr.sin_family &#061; AF_INET;<br \/>\n    server_addr.sin_port &#061; htons(PORT);<br \/>\n    server_addr.sin_addr.s_addr &#061; INADDR_ANY;<\/p>\n<p>    bind(listen_fd, (struct sockaddr*)&amp;server_addr, sizeof(server_addr));<br \/>\n    listen(listen_fd, 5);<br \/>\n    printf(&#034;TCP \u670d\u52a1\u5668\u542f\u52a8&#xff0c;\u76d1\u542c\u7aef\u53e3 %d&#8230;\\\\n&#034;, PORT);<\/p>\n<p>    struct sockaddr_in client_addr;<br \/>\n    socklen_t len &#061; sizeof(client_addr);<\/p>\n<p>    \/\/ \u6838\u5fc3&#xff1a;\u963b\u585e\u7b49\u5f85\u5ba2\u6237\u7aef\u8fde\u63a5<br \/>\n    int conn_fd &#061; accept(listen_fd, (struct sockaddr*)&amp;client_addr, &amp;len);<br \/>\n    printf(&#034;\u63a5\u5230\u5ba2\u6237\u7aef %s:%d\\\\n&#034;, inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));<\/p>\n<p>    char buffer[BUF_SIZE];<br \/>\n    while (1) {<br \/>\n        int n &#061; read(conn_fd, buffer, BUF_SIZE &#8211; 1);<br \/>\n        if (n &gt; 0) {<br \/>\n            buffer[n] &#061; &#039;\\\\0&#039;;<br \/>\n            printf(&#034;\u6536\u5230\u6d88\u606f: %s\\\\n&#034;, buffer);<br \/>\n            write(conn_fd, buffer, n); \/\/ Echo\u56de\u663e<br \/>\n        } else if (n &#061;&#061; 0) {<br \/>\n            \/\/ \u6838\u5fc3&#xff1a;\u5ba2\u6237\u7aef\u65ad\u5f00<br \/>\n            printf(&#034;\u5ba2\u6237\u7aef\u65ad\u5f00\u4e86\u8fde\u63a5\u3002\\\\n&#034;);<br \/>\n            break;<br \/>\n        }<br \/>\n    }<br \/>\n    close(conn_fd);<br \/>\n    close(listen_fd);<br \/>\n    return 0;<br \/>\n}<\/p>\n<h5>\u5ba2\u6237\u7aef tcp_client.c<\/h5>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include &lt;arpa\/inet.h&gt;<\/p>\n<p>#define SERVER_IP &#034;127.0.0.1&#034;<br \/>\n#define PORT 9999<br \/>\n#define BUF_SIZE 1024<\/p>\n<p>int main() {<br \/>\n    int sock_fd &#061; socket(AF_INET, SOCK_STREAM, 0);<br \/>\n    struct sockaddr_in server_addr;<br \/>\n    memset(&amp;server_addr, 0, sizeof(server_addr));<br \/>\n    server_addr.sin_family &#061; AF_INET;<br \/>\n    server_addr.sin_port &#061; htons(PORT);<br \/>\n    inet_pton(AF_INET, SERVER_IP, &amp;server_addr.sin_addr);<\/p>\n<p>    if (connect(sock_fd, (struct sockaddr*)&amp;server_addr, sizeof(server_addr)) &lt; 0) {<br \/>\n        perror(&#034;connect&#034;); return 1;<br \/>\n    }<\/p>\n<p>    char buffer[BUF_SIZE];<br \/>\n    while (1) {<br \/>\n        printf(&#034;\u8bf7\u8f93\u5165: &#034;);<br \/>\n        fgets(buffer, BUF_SIZE, stdin);<br \/>\n        buffer[strcspn(buffer, &#034;\\\\n&#034;)] &#061; 0;<br \/>\n        if (strcmp(buffer, &#034;quit&#034;) &#061;&#061; 0) break;<\/p>\n<p>        write(sock_fd, buffer, strlen(buffer));<br \/>\n        int n &#061; read(sock_fd, buffer, BUF_SIZE &#8211; 1);<br \/>\n        if (n &gt; 0) {<br \/>\n            buffer[n] &#061; &#039;\\\\0&#039;;<br \/>\n            printf(&#034;\u56de\u663e: %s\\\\n&#034;, buffer);<br \/>\n        }<br \/>\n    }<br \/>\n    close(sock_fd);<br \/>\n    return 0;<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"192\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261028190825-6ae2482975459.png\" width=\"712\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"96\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261028190825-6ae24829e43d1.png\" width=\"552\" \/><\/p>\n<p>\u7f16\u8bd1\u8fd0\u884c&#xff1a;\u5f00\u4e24\u4e2a\u7ec8\u7aef&#xff0c;\u8dd1\u8d77\u670d\u52a1\u7aef\u548c\u5ba2\u6237\u7aef&#xff0c;\u53d1\u6d88\u606f\u6d4b\u8bd5\u3002\u6d4b\u8bd5\u5b8c\u5728\u5ba2\u6237\u7aef\u6309 Ctrl&#043;C \u65ad\u5f00&#xff0c;\u770b\u770b\u670d\u52a1\u7aef\u662f\u4e0d\u662f\u6253\u5370\u4e86\u201c\u5ba2\u6237\u7aef\u65ad\u5f00\u201d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x1f4cc; \u6838\u5fc3\u7ed3\u8bba&#xff08;TL;DR&#xff09;&#xff1a;TCP \u6838\u5fc3\u7279\u6027&#xff1a;\u9762\u5411\u8fde\u63a5&#xff08;\u4e09\u6b21\u63e1\u624b&#xff09;\u3001\u53ef\u9760\u4f20\u8f93\u3001\u9762\u5411\u5b57\u8282\u6d41\u3002\u670d\u52a1\u7aef\u4e94\u6b65\u66f2&#xff1a;socket() -&gt; bind() -&gt; listen() -&gt; accept() -&gt; read()\/write()\u3002\u6781\u5176\u91cd\u8981&#xff1a;accept() \u6210\u529f\u540e\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u5168\u65b0\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26 connfd&#xff0c;\u4e13\u95e8\u7528\u4e8e\u548c\u8be5\u5ba2\u6237\u7aef\u901a\u4fe1&amp;#xff0<\/p>\n","protected":false},"author":2,"featured_media":119197,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[58,371,43,305,44],"topic":[],"class_list":["post-119199","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-linux","tag-371","tag-43","tag-305","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Linux \u5b66\u4e60\u7b14\u8bb0\uff08\u56db\u5341\uff09\uff1aTCP \u7f16\u7a0b\u2014\u2014\u4ece\u7406\u8bba\u5230 EchoServer \u5b9e\u6218 - \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\/119199.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linux \u5b66\u4e60\u7b14\u8bb0\uff08\u56db\u5341\uff09\uff1aTCP \u7f16\u7a0b\u2014\u2014\u4ece\u7406\u8bba\u5230 EchoServer \u5b9e\u6218 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"&#x1f4cc; \u6838\u5fc3\u7ed3\u8bba&#xff08;TL;DR&#xff09;&#xff1a;TCP \u6838\u5fc3\u7279\u6027&#xff1a;\u9762\u5411\u8fde\u63a5&#xff08;\u4e09\u6b21\u63e1\u624b&#xff09;\u3001\u53ef\u9760\u4f20\u8f93\u3001\u9762\u5411\u5b57\u8282\u6d41\u3002\u670d\u52a1\u7aef\u4e94\u6b65\u66f2&#xff1a;socket() -&gt; bind() -&gt; listen() -&gt; accept() -&gt; read()\/write()\u3002\u6781\u5176\u91cd\u8981&#xff1a;accept() \u6210\u529f\u540e\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u5168\u65b0\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26 connfd&#xff0c;\u4e13\u95e8\u7528\u4e8e\u548c\u8be5\u5ba2\u6237\u7aef\u901a\u4fe1&amp;#xff0\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/119199.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-28T19:08:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261028190825-6ae2482975459.png\" \/>\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\/119199.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/119199.html\",\"name\":\"Linux \u5b66\u4e60\u7b14\u8bb0\uff08\u56db\u5341\uff09\uff1aTCP \u7f16\u7a0b\u2014\u2014\u4ece\u7406\u8bba\u5230 EchoServer \u5b9e\u6218 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-28T19:08:27+00:00\",\"dateModified\":\"2026-10-28T19:08:27+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/119199.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/119199.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/119199.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux \u5b66\u4e60\u7b14\u8bb0\uff08\u56db\u5341\uff09\uff1aTCP \u7f16\u7a0b\u2014\u2014\u4ece\u7406\u8bba\u5230 EchoServer \u5b9e\u6218\"}]},{\"@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":"Linux \u5b66\u4e60\u7b14\u8bb0\uff08\u56db\u5341\uff09\uff1aTCP \u7f16\u7a0b\u2014\u2014\u4ece\u7406\u8bba\u5230 EchoServer \u5b9e\u6218 - \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\/119199.html","og_locale":"zh_CN","og_type":"article","og_title":"Linux \u5b66\u4e60\u7b14\u8bb0\uff08\u56db\u5341\uff09\uff1aTCP \u7f16\u7a0b\u2014\u2014\u4ece\u7406\u8bba\u5230 EchoServer \u5b9e\u6218 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"&#x1f4cc; \u6838\u5fc3\u7ed3\u8bba&#xff08;TL;DR&#xff09;&#xff1a;TCP \u6838\u5fc3\u7279\u6027&#xff1a;\u9762\u5411\u8fde\u63a5&#xff08;\u4e09\u6b21\u63e1\u624b&#xff09;\u3001\u53ef\u9760\u4f20\u8f93\u3001\u9762\u5411\u5b57\u8282\u6d41\u3002\u670d\u52a1\u7aef\u4e94\u6b65\u66f2&#xff1a;socket() -&gt; bind() -&gt; listen() -&gt; accept() -&gt; read()\/write()\u3002\u6781\u5176\u91cd\u8981&#xff1a;accept() \u6210\u529f\u540e\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u5168\u65b0\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26 connfd&#xff0c;\u4e13\u95e8\u7528\u4e8e\u548c\u8be5\u5ba2\u6237\u7aef\u901a\u4fe1&amp;#xff0","og_url":"https:\/\/www.wsisp.com\/helps\/119199.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-28T19:08:27+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261028190825-6ae2482975459.png"}],"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\/119199.html","url":"https:\/\/www.wsisp.com\/helps\/119199.html","name":"Linux \u5b66\u4e60\u7b14\u8bb0\uff08\u56db\u5341\uff09\uff1aTCP \u7f16\u7a0b\u2014\u2014\u4ece\u7406\u8bba\u5230 EchoServer \u5b9e\u6218 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-28T19:08:27+00:00","dateModified":"2026-10-28T19:08:27+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/119199.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/119199.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/119199.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Linux \u5b66\u4e60\u7b14\u8bb0\uff08\u56db\u5341\uff09\uff1aTCP \u7f16\u7a0b\u2014\u2014\u4ece\u7406\u8bba\u5230 EchoServer \u5b9e\u6218"}]},{"@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\/119199","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=119199"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/119199\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/119197"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=119199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=119199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=119199"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=119199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}