{"id":46485,"date":"2025-07-30T03:16:24","date_gmt":"2025-07-29T19:16:24","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/46485.html"},"modified":"2025-07-30T03:16:24","modified_gmt":"2025-07-29T19:16:24","slug":"c-%e5%8d%8f%e7%a8%8b%e5%bc%8f-tcp-%e7%bd%91%e7%bb%9c%e6%9c%8d%e5%8a%a1%e6%a1%86%e6%9e%b6%ef%bc%9a%e6%9e%84%e5%bb%ba%e9%ab%98%e5%b9%b6%e5%8f%91-echo-%e4%b8%8e%e5%a4%9a%e4%ba%ba%e8%81%8a%e5%a4%a9","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/46485.html","title":{"rendered":"C++ \u534f\u7a0b\u5f0f TCP \u7f51\u7edc\u670d\u52a1\u6846\u67b6\uff1a\u6784\u5efa\u9ad8\u5e76\u53d1 Echo \u4e0e\u591a\u4eba\u804a\u5929\u5ba4\u670d\u52a1\u5668"},"content":{"rendered":"<h3>\u4e00\u3001\u5f15\u8a00&#xff1a;\u4e3a\u4f55\u7528\u534f\u7a0b\u5199\u7f51\u7edc\u670d\u52a1&#xff1f;<\/h3>\n<p>\u4f20\u7edf C&#043;&#043; \u7f51\u7edc\u670d\u52a1\u5668\u4e00\u822c\u4f7f\u7528\u5982\u4e0b\u65b9\u5f0f&#xff1a;<\/p>\n<ul>\n<li>\n<p>select() \u6216 epoll() &#043; \u72b6\u6001\u673a<\/p>\n<\/li>\n<li>\n<p>\u591a\u7ebf\u7a0b per-connection&#xff08;\u7ebf\u7a0b\u7206\u70b8\u95ee\u9898&#xff09;<\/p>\n<\/li>\n<li>\n<p>Boost.Asio&#xff08;\u590d\u6742\u56de\u8c03\u5d4c\u5957&#xff09;<\/p>\n<\/li>\n<\/ul>\n<p>C&#043;&#043;20 \u534f\u7a0b\u5e26\u6765\u975e\u963b\u585e\u3001\u65e0\u56de\u8c03\u3001\u7b80\u6d01\u6e05\u6670\u7684\u5f02\u6b65 IO \u7f16\u7a0b\u65b9\u5f0f\u3002\u6211\u4eec\u53ef\u4ee5\u6784\u5efa\u4e00\u4e2a\u8f7b\u91cf\u7684\u534f\u7a0b\u5f0f TCP \u7f51\u7edc\u670d\u52a1\u5668\u6846\u67b6&#xff0c;\u652f\u6301\u6570\u767e\u751a\u81f3\u4e0a\u5343\u5e76\u53d1\u8fde\u63a5&#xff0c;\u903b\u8f91\u7b80\u6d01&#xff0c;\u6027\u80fd\u4f18\u5f02\u3002<\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u672c\u6587\u76ee\u6807<\/h3>\n<p>\u5b9e\u73b0\u4e00\u4e2a\u534f\u7a0b\u9a71\u52a8\u7684\u7f51\u7edc\u670d\u52a1\u6846\u67b6&#xff0c;\u5177\u5907\u4ee5\u4e0b\u7279\u6027&#xff1a;<\/p>\n<table>\n<tr>\u529f\u80fd\u63cf\u8ff0<\/tr>\n<tbody>\n<tr>\n<td>\u534f\u7a0b\u5904\u7406\u5ba2\u6237\u7aef\u8fde\u63a5<\/td>\n<td>\u6bcf\u4e2a\u8fde\u63a5\u7531\u4e00\u4e2a\u534f\u7a0b\u5904\u7406&#xff0c;\u907f\u514d\u7ebf\u7a0b\u5806\u53e0<\/td>\n<\/tr>\n<tr>\n<td>\u975e\u963b\u585e\u8bfb\u5199\u5c01\u88c5<\/td>\n<td>\u4f7f\u7528\u534f\u7a0b\u6302\u8d77\u7b49\u5f85 socket \u8bfb\u5199<\/td>\n<\/tr>\n<tr>\n<td>Echo \u6a21\u5f0f<\/td>\n<td>\u5ba2\u6237\u7aef\u53d1\u4ec0\u4e48\u5c31\u56de\u4ec0\u4e48<\/td>\n<\/tr>\n<tr>\n<td>\u804a\u5929\u5ba4\u6a21\u5f0f&#xff08;\u652f\u6301\u5207\u6362&#xff09;<\/td>\n<td>\u6240\u6709\u8fde\u63a5\u5171\u4eab\u5e7f\u64ad\u6d88\u606f<\/td>\n<\/tr>\n<tr>\n<td>\u8fde\u63a5\u751f\u547d\u5468\u671f\u7ba1\u7406<\/td>\n<td>\u81ea\u52a8\u5173\u95ed\u3001\u9519\u8bef\u5904\u7406\u3001\u9632\u5d29\u6e83<\/td>\n<\/tr>\n<tr>\n<td>\u652f\u6301 Linux \u5e73\u53f0\u539f\u751f epoll<\/td>\n<td>\u4f7f\u7528 epoll \u9a71\u52a8 socket \u4e0e\u534f\u7a0b\u8c03\u5ea6<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u4e09\u3001\u6574\u4f53\u67b6\u6784\u56fe<\/h3>\n<p>lua<\/p>\n<p>\u590d\u5236\u7f16\u8f91<\/p>\n<p>&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#043; | TCP \u76d1\u542c\u5668 | &#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#043; | &#043;&#8212;&#8211;v&#8212;&#8211;&#043; | \u65b0\u8fde\u63a5\u534f\u7a0b | &#8212;&gt; \u521b\u5efa Client \u534f\u7a0b &#043;&#8212;&#8211;&#043;&#8212;&#8211;&#043; | &#043;&#8212;&#8212;&#8212;v&#8212;&#8212;&#8212;-&#043; &#043;&#8212;&#8212;&#8212;&#043; | Client \u534f\u7a0b | &lt;&#8212;&gt; | socket | | \u8bfb\u5199\u6d88\u606f &#043; \u5e7f\u64ad | &#043;&#8212;&#8212;&#8212;&#043; &#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#043; <\/p>\n<hr \/>\n<h3>\u56db\u3001\u57fa\u7840\u6a21\u5757\u4e00\u89c8<\/h3>\n<table>\n<tr>\u6a21\u5757\u6587\u4ef6\u4f5c\u7528<\/tr>\n<tbody>\n<tr>\n<td>socket.hpp<\/td>\n<td>socket API \u5c01\u88c5<\/td>\n<\/tr>\n<tr>\n<td>awaitable.hpp<\/td>\n<td>\u534f\u7a0b\u7b49\u5f85\u5c01\u88c5&#xff08;read\/write&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>server.hpp<\/td>\n<td>\u4e3b\u670d\u52a1\u5668\u63a7\u5236\u5668<\/td>\n<\/tr>\n<tr>\n<td>client.hpp<\/td>\n<td>\u5ba2\u6237\u7aef\u534f\u7a0b\u63a7\u5236\u5668<\/td>\n<\/tr>\n<tr>\n<td>epoll_loop.hpp<\/td>\n<td>epoll \u9a71\u52a8\u4e8b\u4ef6\u5206\u53d1\u4e0e resume<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u4e94\u3001epoll \u534f\u7a0b\u7b49\u5f85\u5b9e\u73b0\u6838\u5fc3\u601d\u60f3<\/h3>\n<p>cpp<\/p>\n<p>\u590d\u5236\u7f16\u8f91<\/p>\n<p>\/\/ \u4f2a\u4ee3\u7801\u7ed3\u6784 co_await socket_read(sockfd, buffer, len); \/\/ 1. \u6ce8\u518c sockfd \u5230 epoll \/\/ 2. \u534f\u7a0b\u6302\u8d77&#xff0c;\u7b49\u5f85 IO \u5c31\u7eea \/\/ 3. epoll \u8fd4\u56de\u540e resume \u534f\u7a0b <\/p>\n<p>\u8fd9\u7c7b\u4f3c\u4e8e async\/await \u7684\u5f02\u6b65 IO \u6a21\u578b&#xff0c;\u4f46\u662f\u6211\u4eec\u81ea\u5df1\u7528 C&#043;&#043;20 \u539f\u8bed\u6784\u5efa\u7684\u3002<\/p>\n<hr \/>\n<h3>\u516d\u3001Awaitable \u5c01\u88c5&#xff08;\u4ee5 read \u4e3a\u4f8b&#xff09;<\/h3>\n<p>cpp<\/p>\n<p>\u590d\u5236\u7f16\u8f91<\/p>\n<p>struct ReadAwaiter { int fd; char* buffer; size_t length; ssize_t result; ReadAwaiter(int fd, char* buf, size_t len) : fd(fd), buffer(buf), length(len), result(0) {} bool await_ready() const noexcept { return false; } void await_suspend(std::coroutine_handle&lt;&gt; h) { register_epoll_read(fd, h); \/\/ \u6ce8\u518c\u8bfb\u4e8b\u4ef6 } ssize_t await_resume() const noexcept { return result; } }; <\/p>\n<p>\u4f60\u9700\u8981\u7ef4\u62a4\u4e00\u4e2a epoll_loop \u5faa\u73af\u6765\u76d1\u542c\u6240\u6709\u6302\u8d77\u7684 fd \u4e0e\u534f\u7a0b resume\u3002<\/p>\n<hr \/>\n<h3>\u4e03\u3001Socket API \u7b80\u5316\u5c01\u88c5<\/h3>\n<p>cpp<\/p>\n<p>\u590d\u5236\u7f16\u8f91<\/p>\n<p>int create_server_socket(int port) { int sockfd &#061; socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0); int opt &#061; 1; setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &amp;opt, sizeof(opt)); sockaddr_in addr &#061; {AF_INET, htons(port), INADDR_ANY}; bind(sockfd, (sockaddr*)&amp;addr, sizeof(addr)); listen(sockfd, SOMAXCONN); return sockfd; } <\/p>\n<hr \/>\n<h3>\u516b\u3001\u5ba2\u6237\u7aef\u534f\u7a0b\u903b\u8f91&#xff1a;Echo \u6a21\u5f0f<\/h3>\n<p>cpp<\/p>\n<p>\u590d\u5236\u7f16\u8f91<\/p>\n<p>Task&lt;&gt; handle_client(int client_fd) { char buf[1024]; try { while (true) { ssize_t n &#061; co_await ReadAwaiter(client_fd, buf, sizeof(buf)); if (n &lt;&#061; 0) break; std::cout &lt;&lt; &#034;[client] \u6536\u5230: &#034; &lt;&lt; std::string(buf, n) &lt;&lt; &#034;\\\\n&#034;; ssize_t m &#061; write(client_fd, buf, n); \/\/ \u7b80\u5316\u5199 if (m &lt;&#061; 0) break; } } catch (&#8230;) { std::cout &lt;&lt; &#034;[client] \u5f02\u5e38\u65ad\u5f00\\\\n&#034;; } close(client_fd); co_return; } <\/p>\n<hr \/>\n<h3>\u4e5d\u3001\u804a\u5929\u5ba4\u652f\u6301&#xff1a;\u5171\u4eab\u5e7f\u64ad\u6c60<\/h3>\n<p>cpp<\/p>\n<p>\u590d\u5236\u7f16\u8f91<\/p>\n<p>std::set&lt;int&gt; all_clients; std::mutex client_mtx; void broadcast_to_all(const std::string&amp; msg, int exclude &#061; -1) { std::lock_guard&lt;std::mutex&gt; lock(client_mtx); for (int fd : all_clients) { if (fd &#061;&#061; exclude) continue; write(fd, msg.c_str(), msg.size()); } } <\/p>\n<p>\u66ff\u6362\u4e0a\u9762\u7684 write() \u4e3a&#xff1a;<\/p>\n<p>cpp<\/p>\n<p>\u590d\u5236\u7f16\u8f91<\/p>\n<p>broadcast_to_all(std::string(buf, n), client_fd); <\/p>\n<hr \/>\n<h3>\u5341\u3001\u534f\u7a0b\u4e3b\u76d1\u542c\u5668<\/h3>\n<p>cpp<\/p>\n<p>\u590d\u5236\u7f16\u8f91<\/p>\n<p>Task&lt;&gt; server_loop(int listen_fd) { while (true) { int client_fd &#061; accept(listen_fd, nullptr, nullptr); if (client_fd &gt;&#061; 0) { fcntl(client_fd, F_SETFL, O_NONBLOCK); { std::lock_guard&lt;std::mutex&gt; lock(client_mtx); all_clients.insert(client_fd); } handle_client(client_fd).start(); \/\/ \u534f\u7a0b\u5316\u5904\u7406 } else { std::this_thread::sleep_for(std::chrono::milliseconds(10)); } } } <\/p>\n<hr \/>\n<h3>\u5341\u4e00\u3001epoll \u534f\u7a0b\u4e8b\u4ef6\u8c03\u5ea6\u6838\u5fc3&#xff08;\u4f2a\u7801&#xff09;<\/h3>\n<p>\u4f60\u9700\u8981\u7ef4\u62a4\u5982\u4e0b\u7ed3\u6784&#xff1a;<\/p>\n<p>cpp<\/p>\n<p>\u590d\u5236\u7f16\u8f91<\/p>\n<p>std::unordered_map&lt;int, std::coroutine_handle&lt;&gt;&gt; read_waiters; void register_epoll_read(int fd, std::coroutine_handle&lt;&gt; h) { read_waiters[fd] &#061; h; epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &#8230;); } <\/p>\n<p>\u5728 epoll_wait() \u4e2d&#xff1a;<\/p>\n<p>cpp<\/p>\n<p>\u590d\u5236\u7f16\u8f91<\/p>\n<p>for (each ready fd) { auto h &#061; read_waiters[fd]; if (h) h.resume(); read_waiters.erase(fd); } <\/p>\n<hr \/>\n<h3>\u5341\u4e8c\u3001\u4e3b\u51fd\u6570\u5165\u53e3<\/h3>\n<p>cpp<\/p>\n<p>\u590d\u5236\u7f16\u8f91<\/p>\n<p>int main() { int port &#061; 9000; int listen_fd &#061; create_server_socket(port); std::cout &lt;&lt; &#034;\u670d\u52a1\u5668\u76d1\u542c\u7aef\u53e3&#xff1a;&#034; &lt;&lt; port &lt;&lt; &#034;\\\\n&#034;; server_loop(listen_fd).start(); \/\/ \u542f\u52a8 epoll \u4e3b\u5faa\u73af&#xff08;\u9700\u8981\u53e6\u5f00\u7ebf\u7a0b&#xff09; epoll_loop(); \/\/ \u6301\u7eed\u8c03\u5ea6\u6302\u8d77\u534f\u7a0b return 0; } <\/p>\n<hr \/>\n<h3>\u5341\u4e09\u3001\u8fd0\u884c\u6d4b\u8bd5<\/h3>\n<p>\u4f60\u53ef\u4ee5\u4f7f\u7528\u591a\u4e2a telnet \u5ba2\u6237\u7aef\u6d4b\u8bd5&#xff1a;<\/p>\n<p>bash<\/p>\n<p>\u590d\u5236\u7f16\u8f91<\/p>\n<p>telnet 127.0.0.1 9000 <\/p>\n<h4>Echo \u6a21\u5f0f&#xff1a;<\/h4>\n<p>\u590d\u5236\u7f16\u8f91<\/p>\n<p>\u5ba2\u6237\u7aef\u53d1\u9001&#xff1a;hello \u670d\u52a1\u5668\u56de\u5e94&#xff1a;hello <\/p>\n<h4>\u804a\u5929\u5ba4\u6a21\u5f0f&#xff1a;<\/h4>\n<p>\u590d\u5236\u7f16\u8f91<\/p>\n<p>\u5ba2\u6237\u7aef1&#xff1a;hello \u5ba2\u6237\u7aef2&#xff1a;hello&#xff08;\u6765\u81ea\u5ba2\u6237\u7aef1&#xff09; <\/p>\n<hr \/>\n<h3>\u5341\u56db\u3001\u6027\u80fd\u4e0e\u4f18\u52bf<\/h3>\n<table>\n<tr>\u7279\u6027\u4f18\u52bf\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u4f4e\u5f00\u9500<\/td>\n<td>\u534f\u7a0b\u8c03\u5ea6\u65e0\u9700\u7ebf\u7a0b\u5207\u6362<\/td>\n<\/tr>\n<tr>\n<td>\u9ad8\u5e76\u53d1<\/td>\n<td>\u53ef\u8f7b\u677e\u652f\u6301\u4e0a\u5343\u8fde\u63a5<\/td>\n<\/tr>\n<tr>\n<td>\u53ef\u8bfb\u6027\u5f3a<\/td>\n<td>\u903b\u8f91\u7ed3\u6784\u987a\u5e8f\u76f4\u89c2&#xff0c;\u907f\u514d\u56de\u8c03\u5730\u72f1<\/td>\n<\/tr>\n<tr>\n<td>\u6613\u4e8e\u6269\u5c55<\/td>\n<td>\u6a21\u5757\u6e05\u6670&#xff0c;\u53ef\u52a0\u5165\u52a0\u5bc6\u3001\u9a8c\u8bc1\u3001\u534f\u8bae\u5904\u7406\u7b49<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u5341\u4e94\u3001\u6269\u5c55\u5efa\u8bae<\/h3>\n<table>\n<tr>\u529f\u80fd\u9879\u5b9e\u73b0\u65b9\u5f0f\u7b80\u8ff0<\/tr>\n<tbody>\n<tr>\n<td>WebSocket \u652f\u6301<\/td>\n<td>\u5c01\u88c5\u5e27\u534f\u8bae\u5e76\u6539\u5199 read\/write \u534f\u7a0b<\/td>\n<\/tr>\n<tr>\n<td>\u7528\u6237\u8eab\u4efd\u8bc6\u522b<\/td>\n<td>\u5728\u8fde\u63a5\u534f\u7a0b\u4e2d\u6dfb\u52a0\u8ba4\u8bc1\u9636\u6bb5<\/td>\n<\/tr>\n<tr>\n<td>JSON \u534f\u8bae\u5c01\u88c5<\/td>\n<td>\u7ed3\u5408 nlohmann\/json \u89e3\u6790\u5ba2\u6237\u7aef\u6d88\u606f<\/td>\n<\/tr>\n<tr>\n<td>REST &#043; Chat \u670d\u52a1<\/td>\n<td>HTTP \u4e0e\u804a\u5929\u5ba4\u670d\u52a1\u5171\u7528\u7aef\u53e3&#xff0c;\u8def\u5f84\u533a\u5206<\/td>\n<\/tr>\n<tr>\n<td>TLS \u52a0\u5bc6\u652f\u6301<\/td>\n<td>\u4f7f\u7528 OpenSSL \u914d\u5408\u975e\u963b\u585e BIO \u5c01\u88c5\u534f\u7a0b I\/O<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u5341\u516d\u3001\u603b\u7ed3<\/h3>\n<p>\u672c\u9879\u76ee\u5b9e\u73b0\u4e86&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4e00\u4e2a\u57fa\u4e8e C&#043;&#043; \u534f\u7a0b\u7684 TCP \u7f51\u7edc\u670d\u52a1\u6846\u67b6<\/p>\n<\/li>\n<li>\n<p>\u6bcf\u4e2a\u5ba2\u6237\u7aef\u7531\u534f\u7a0b\u72ec\u7acb\u5904\u7406<\/p>\n<\/li>\n<li>\n<p>\u652f\u6301 Echo \u6a21\u5f0f\u4e0e\u804a\u5929\u5ba4\u5e7f\u64ad\u6a21\u5f0f<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528 epoll \u9a71\u52a8\u5f02\u6b65\u534f\u7a0b\u8c03\u5ea6<\/p>\n<\/li>\n<li>\n<p>\u6784\u5efa\u4e86\u57fa\u7840\u7684\u534f\u7a0b\u5f0f\u9ad8\u5e76\u53d1\u7f51\u7edc\u6a21\u578b<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb851\u6b21\uff0c\u70b9\u8d5e7\u6b21\uff0c\u6536\u85cf28\u6b21\u3002\u672c\u9879\u76ee\u5b9e\u73b0\u4e86\uff1a\u4e00\u4e2a\u57fa\u4e8e C++ \u534f\u7a0b\u7684 TCP \u7f51\u7edc\u670d\u52a1\u6846\u67b6\u6bcf\u4e2a\u5ba2\u6237\u7aef\u7531\u534f\u7a0b\u72ec\u7acb\u5904\u7406\u652f\u6301 Echo \u6a21\u5f0f\u4e0e\u804a\u5929\u5ba4\u5e7f\u64ad\u6a21\u5f0f\u4f7f\u7528 epoll \u9a71\u52a8\u5f02\u6b65\u534f\u7a0b\u8c03\u5ea6\u6784\u5efa\u4e86\u57fa\u7840\u7684\u534f\u7a0b\u5f0f\u9ad8\u5e76\u53d1\u7f51\u7edc\u6a21\u578bXX=Ybj0X=eOsMqo=ImGk=EiDX=hYImG=kEiCgA=e8c6=a4A8=ZSmQE=L5Z3W0=USwQ=uOfJ=dHbE2=9tNrLp=JnHl=FjLq=qNR5s=zjDhBf=97b5=Z3\u3002_\u5f00\u6e90 c++ tcp\u9ad8\u5e76\u53d1\u6846\u67b6<\/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":[55,205,43],"topic":[],"class_list":["post-46485","post","type-post","status-publish","format-standard","hentry","category-server","tag-c","tag-tcp-ip","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C++ \u534f\u7a0b\u5f0f TCP \u7f51\u7edc\u670d\u52a1\u6846\u67b6\uff1a\u6784\u5efa\u9ad8\u5e76\u53d1 Echo \u4e0e\u591a\u4eba\u804a\u5929\u5ba4\u670d\u52a1\u5668 - \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\/46485.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++ \u534f\u7a0b\u5f0f TCP \u7f51\u7edc\u670d\u52a1\u6846\u67b6\uff1a\u6784\u5efa\u9ad8\u5e76\u53d1 Echo \u4e0e\u591a\u4eba\u804a\u5929\u5ba4\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb851\u6b21\uff0c\u70b9\u8d5e7\u6b21\uff0c\u6536\u85cf28\u6b21\u3002\u672c\u9879\u76ee\u5b9e\u73b0\u4e86\uff1a\u4e00\u4e2a\u57fa\u4e8e C++ \u534f\u7a0b\u7684 TCP \u7f51\u7edc\u670d\u52a1\u6846\u67b6\u6bcf\u4e2a\u5ba2\u6237\u7aef\u7531\u534f\u7a0b\u72ec\u7acb\u5904\u7406\u652f\u6301 Echo \u6a21\u5f0f\u4e0e\u804a\u5929\u5ba4\u5e7f\u64ad\u6a21\u5f0f\u4f7f\u7528 epoll \u9a71\u52a8\u5f02\u6b65\u534f\u7a0b\u8c03\u5ea6\u6784\u5efa\u4e86\u57fa\u7840\u7684\u534f\u7a0b\u5f0f\u9ad8\u5e76\u53d1\u7f51\u7edc\u6a21\u578bXX=Ybj0X=eOsMqo=ImGk=EiDX=hYImG=kEiCgA=e8c6=a4A8=ZSmQE=L5Z3W0=USwQ=uOfJ=dHbE2=9tNrLp=JnHl=FjLq=qNR5s=zjDhBf=97b5=Z3\u3002_\u5f00\u6e90 c++ tcp\u9ad8\u5e76\u53d1\u6846\u67b6\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/46485.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-29T19:16:24+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\/46485.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/46485.html\",\"name\":\"C++ \u534f\u7a0b\u5f0f TCP \u7f51\u7edc\u670d\u52a1\u6846\u67b6\uff1a\u6784\u5efa\u9ad8\u5e76\u53d1 Echo \u4e0e\u591a\u4eba\u804a\u5929\u5ba4\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-29T19:16:24+00:00\",\"dateModified\":\"2025-07-29T19:16:24+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/46485.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/46485.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/46485.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++ \u534f\u7a0b\u5f0f TCP \u7f51\u7edc\u670d\u52a1\u6846\u67b6\uff1a\u6784\u5efa\u9ad8\u5e76\u53d1 Echo \u4e0e\u591a\u4eba\u804a\u5929\u5ba4\u670d\u52a1\u5668\"}]},{\"@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":"C++ \u534f\u7a0b\u5f0f TCP \u7f51\u7edc\u670d\u52a1\u6846\u67b6\uff1a\u6784\u5efa\u9ad8\u5e76\u53d1 Echo \u4e0e\u591a\u4eba\u804a\u5929\u5ba4\u670d\u52a1\u5668 - \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\/46485.html","og_locale":"zh_CN","og_type":"article","og_title":"C++ \u534f\u7a0b\u5f0f TCP \u7f51\u7edc\u670d\u52a1\u6846\u67b6\uff1a\u6784\u5efa\u9ad8\u5e76\u53d1 Echo \u4e0e\u591a\u4eba\u804a\u5929\u5ba4\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb851\u6b21\uff0c\u70b9\u8d5e7\u6b21\uff0c\u6536\u85cf28\u6b21\u3002\u672c\u9879\u76ee\u5b9e\u73b0\u4e86\uff1a\u4e00\u4e2a\u57fa\u4e8e C++ \u534f\u7a0b\u7684 TCP \u7f51\u7edc\u670d\u52a1\u6846\u67b6\u6bcf\u4e2a\u5ba2\u6237\u7aef\u7531\u534f\u7a0b\u72ec\u7acb\u5904\u7406\u652f\u6301 Echo \u6a21\u5f0f\u4e0e\u804a\u5929\u5ba4\u5e7f\u64ad\u6a21\u5f0f\u4f7f\u7528 epoll \u9a71\u52a8\u5f02\u6b65\u534f\u7a0b\u8c03\u5ea6\u6784\u5efa\u4e86\u57fa\u7840\u7684\u534f\u7a0b\u5f0f\u9ad8\u5e76\u53d1\u7f51\u7edc\u6a21\u578bXX=Ybj0X=eOsMqo=ImGk=EiDX=hYImG=kEiCgA=e8c6=a4A8=ZSmQE=L5Z3W0=USwQ=uOfJ=dHbE2=9tNrLp=JnHl=FjLq=qNR5s=zjDhBf=97b5=Z3\u3002_\u5f00\u6e90 c++ tcp\u9ad8\u5e76\u53d1\u6846\u67b6","og_url":"https:\/\/www.wsisp.com\/helps\/46485.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-29T19:16:24+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\/46485.html","url":"https:\/\/www.wsisp.com\/helps\/46485.html","name":"C++ \u534f\u7a0b\u5f0f TCP \u7f51\u7edc\u670d\u52a1\u6846\u67b6\uff1a\u6784\u5efa\u9ad8\u5e76\u53d1 Echo \u4e0e\u591a\u4eba\u804a\u5929\u5ba4\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-29T19:16:24+00:00","dateModified":"2025-07-29T19:16:24+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/46485.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/46485.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/46485.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"C++ \u534f\u7a0b\u5f0f TCP \u7f51\u7edc\u670d\u52a1\u6846\u67b6\uff1a\u6784\u5efa\u9ad8\u5e76\u53d1 Echo \u4e0e\u591a\u4eba\u804a\u5929\u5ba4\u670d\u52a1\u5668"}]},{"@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\/46485","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=46485"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/46485\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=46485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=46485"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=46485"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=46485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}