{"id":34020,"date":"2025-04-28T22:15:38","date_gmt":"2025-04-28T14:15:38","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/34020.html"},"modified":"2025-04-28T22:15:38","modified_gmt":"2025-04-28T14:15:38","slug":"%e6%9e%84%e5%bb%batcp%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%9a%e4%bb%8e%e5%9f%ba%e7%a1%80%e5%88%b0%e7%ba%bf%e7%a8%8b%e6%b1%a0%e7%89%88%e6%9c%ac%e7%9a%84%e5%ae%9e%e7%8e%b0%e4%b8%8e%e6%b5%8b%e8%af%95","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/34020.html","title":{"rendered":"\u6784\u5efaTCP\u670d\u52a1\u5668\uff1a\u4ece\u57fa\u7840\u5230\u7ebf\u7a0b\u6c60\u7248\u672c\u7684\u5b9e\u73b0\u4e0e\u6d4b\u8bd5\u8be6\u89e3"},"content":{"rendered":"<p>\u76ee\u5f55<\/p>\n<p>1\u3001TcpServerMain.cc<\/p>\n<p>2\u3001TcpServer.hpp<\/p>\n<p>2.1\u3001TcpServer\u7c7b\u57fa\u672c\u7ed3\u6784<\/p>\n<p>2.2\u3001\u6784\u9020\u6790\u6784\u51fd\u6570<\/p>\n<p>2.3\u3001InitServer()<\/p>\n<p>2.4\u3001Loop()<\/p>\n<p>2.4.1\u3001Server 0(\u4e0d\u9760\u8c31\u7248\u672c)<\/p>\n<p>2.4.2\u3001Server 1(\u591a\u8fdb\u7a0b\u7248\u672c)<\/p>\n<p>2.4.3\u3001Server 2(\u591a\u7ebf\u7a0b\u7248\u672c)<\/p>\n<p>2.4.4\u3001Server 3(\u7ebf\u7a0b\u6c60\u7248\u672c)<\/p>\n<p>3\u3001TcpClientMain.cc<\/p>\n<p>4\u3001\u6d4b\u8bd5\u7ed3\u679c<\/p>\n<p>4.1\u3001\u4e0d\u9760\u8c31\u7248\u672c<\/p>\n<p>4.2\u3001\u591a\u8fdb\u7a0b\u7248\u672c<\/p>\n<p>4.3\u3001\u591a\u7ebf\u7a0b\u7248\u672c<\/p>\n<p>4.4\u3001\u7ebf\u7a0b\u6c60\u7248\u672c<\/p>\n<p>5\u3001\u5b8c\u6574\u4ee3\u7801<\/p>\n<p>5.1\u3001Makefile<\/p>\n<p>5.2\u3001TcpClientMain.cc<\/p>\n<p>5.3\u3001TcpServer.hpp<\/p>\n<p>5.4\u3001TcpServerMain.cc<\/p>\n<p>\u524d\u9762\u51e0\u5f39\u4f7f\u7528UDP\u534f\u8bae\u5b9e\u73b0\u4e86\u76f8\u5173\u529f\u80fd&#xff0c;\u6b64\u5f39\u4f7f\u7528TCP\u534f\u8bae\u5b9e\u73b0\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u7aef\u7684\u901a\u4fe1&#xff0c;\u76f8\u6bd4\u4e0eUDP\u534f\u8bae&#xff0c;TCP\u534f\u8bae\u66f4\u52a0\u53ef\u9760&#xff0c;\u4e5f\u66f4\u52a0\u590d\u6742&#xff01;\u4e0eUDP\u7c7b\u4f3c&#xff0c;\u6211\u4eec\u5148\u5199\u4e3b\u51fd\u6570&#xff0c;\u7136\u540e\u5b9e\u73b0\u76f8\u5173\u51fd\u6570&#xff01;<\/p>\n<p>1\u3001TcpServerMain.cc \u670d\u52a1\u7aef\u4e3b\u51fd\u6570\u4f7f\u7528\u667a\u80fd\u6307\u9488\u6784\u9020Server\u5bf9\u8c61&#xff0c;\u7136\u540e\u8c03\u7528\u521d\u59cb\u5316\u4e0e\u6267\u884c\u51fd\u6570&#xff0c;\u8c03\u7528\u4e3b\u51fd\u6570\u4f7f\u7528\u8be5\u53ef\u6267\u884c\u7a0b\u5e8f &#043; \u7aef\u53e3\u53f7&#xff01;<\/p>\n<p>\/\/ .\/tcpserver 8888 int main(int argc,char* argv[]) { \u00a0 \u00a0 if(argc !&#061; 2) \u00a0 \u00a0 { \u00a0 \u00a0 \u00a0 \u00a0 std::cerr &lt;&lt; &#034;Usage: &#034; &lt;&lt; argv[0] &lt;&lt; &#034; local-post&#034; &lt;&lt; std::endl; \u00a0 \u00a0 \u00a0 \u00a0 exit(0); \u00a0 \u00a0 } \u00a0 \u00a0 \u00a0 uint16_t port &#061; std::stoi(argv[1]); \u00a0 \u00a0 \u00a0 std::unique_ptr&lt;TcpServer&gt; tsvr &#061; std::make_unique&lt;TcpServer&gt;(port); \u00a0 \u00a0 \u00a0 tsvr-&gt;InitServer(); \u00a0 \u00a0 tsvr-&gt;Loop(); \u00a0 \u00a0 return 0; }<\/p>\n<p>2\u3001TcpServer.hpp TcpServer.hpp\u5c01\u88c5TcpServer\u7c7b&#xff01;<\/p>\n<p>\u679a\u4e3e\u5e38\u91cf&#xff1a;<\/p>\n<p>enum\u00a0 { \u00a0 \u00a0 SOCKET_ERROR, \u00a0 \u00a0 BIND_ERROR, \u00a0 \u00a0 LISTEN_ERROR }; \u5168\u5c40\u9759\u6001\u53d8\u91cf&#xff1a;<\/p>\n<p>const static uint16_t gport &#061; 8888; const static int gsockfd &#061; -1; const static int gblcklog &#061; 8; 2.1\u3001TcpServer\u7c7b\u57fa\u672c\u7ed3\u6784 TcpServer\u7c7b\u7684\u57fa\u672c\u6210\u5458\u6709\u7aef\u53e3\u53f7&#xff0c;\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff0c;\u4e0e\u8fd0\u884c\u72b6\u6001&#xff01;<\/p>\n<p>\/\/ \u9762\u5411\u5b57\u8282\u6d41 class TcpServer { public: \u00a0 \u00a0 TcpServer(uint16_t port &#061; gport); \u00a0 \u00a0 void InitServer(); \u00a0 \u00a0 void Loop(); \u00a0 \u00a0 ~TcpServer(); private: \u00a0 \u00a0 uint16_t _port; \u00a0 \u00a0 int _sockfd; \/\/ TODO \u00a0 \u00a0 bool _isrunning; }; 2.2\u3001\u6784\u9020\u6790\u6784\u51fd\u6570 \u00a0\u6784\u9020\u51fd\u6570\u521d\u59cb\u5316\u6210\u5458\u53d8\u91cf&#xff0c;\u6790\u6784\u51fd\u6570\u65e0\u9700\u5904\u7406&#xff01;<\/p>\n<p>\u6ce8\u610f&#xff1a;\u6b64\u5904\u9700\u8981\u7528\u5230\u4e24\u4e2a\u5168\u5c40\u9759\u6001\u53d8\u91cf&#xff01;\u00a0<\/p>\n<p>TcpServer(uint16_t port &#061; gport) \u00a0 \u00a0 :_port(port),_sockfd(gsockfd),_isrunning(false) {} \u00a0 ~TcpServer() {} 2.3\u3001InitServer() InitServer() \u521d\u59cb\u5316\u670d\u52a1\u7aef&#xff01;<\/p>\n<p>\u521d\u59cb\u5316\u51fd\u6570\u4e3b\u8981\u5206\u4e3a\u4e09\u6b65&#xff1a;<\/p>\n<p>1\u3001\u521b\u5efasocket(\u7c7b\u578b\u4e0eUDP\u4e0d\u540c) \u7c7b\u578b\u9700\u8981\u4f7f\u7528 SOCK_STREAM<\/p>\n<p>2\u3001bind sockfd \u548c socket addr 3\u3001\u83b7\u53d6\u8fde\u63a5(\u4e0eUDP\u4e0d\u540c) \u83b7\u53d6\u8fde\u63a5\u9700\u8981\u4f7f\u7528listen\u51fd\u6570(\u5c06\u5957\u63a5\u5b57\u8bbe\u7f6e\u4e3a\u76d1\u542c\u6a21\u5f0f&#xff0c;\u4ee5\u4fbf\u80fd\u591f\u63a5\u53d7\u8fdb\u5165\u7684\u8fde\u63a5\u8bf7\u6c42)<\/p>\n<p>listen()<\/p>\n<p>#include &lt;sys\/types.h&gt; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 #include &lt;sys\/socket.h&gt; \u00a0 int listen(int sockfd, int backlog);<\/p>\n<p> \u53c2\u6570<\/p>\n<p>sockfd&#xff1a;\u8fd9\u662f\u4e00\u4e2a\u5df2\u521b\u5efa\u7684\u5957\u63a5\u5b57\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff0c;\u5b83\u5e94\u8be5\u662f\u4e00\u4e2a\u7ed1\u5b9a\u5230\u67d0\u4e2a\u5730\u5740\u548c\u7aef\u53e3\u7684\u5957\u63a5\u5b57\u3002 backlog&#xff1a;\u8fd9\u4e2a\u53c2\u6570\u5b9a\u4e49\u4e86\u5185\u6838\u5e94\u8be5\u4e3a\u76f8\u5e94\u5957\u63a5\u5b57\u6392\u961f\u7684\u6700\u5927\u8fde\u63a5\u6570(\u6b64\u5904\u6682\u65f6\u4f7f\u75288)\u3002\u5982\u679c\u961f\u5217\u5df2\u6ee1&#xff0c;\u65b0\u7684\u8fde\u63a5\u8bf7\u6c42\u53ef\u80fd\u4f1a\u88ab\u62d2\u7edd\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f&#xff0c;\u8fd9\u4e2a\u503c\u53ea\u662f\u5185\u6838\u7528\u4e8e\u4f18\u5316\u6027\u80fd\u7684\u4e00\u4e2a\u63d0\u793a&#xff0c;\u5b9e\u9645\u5b9e\u73b0\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\u3002 \u8fd4\u56de\u503c<\/p>\n<p>\u6210\u529f\u65f6&#xff0c;listen \u51fd\u6570\u8fd4\u56de 0\u3002 \u5931\u8d25\u65f6&#xff0c;\u8fd4\u56de -1&#xff0c;\u5e76\u8bbe\u7f6e errno \u4ee5\u6307\u793a\u9519\u8bef\u7c7b\u578b\u3002 \u6ce8\u610f&#xff1a;\u6b64\u5904\u9700\u8981\u7528\u5230\u5168\u5c40\u9759\u6001\u53d8\u91cf\u548c\u679a\u4e3e\u5e38\u91cf&#xff01;<\/p>\n<p>\/\/ _sockfd \u7248\u672c void InitServer() { \u00a0 \u00a0 \/\/ 1.\u521b\u5efasocket \u00a0 \u00a0 _sockfd &#061; ::socket(AF_INET,SOCK_STREAM,0); \u00a0 \u00a0 if(_sockfd &lt; 0) \u00a0 \u00a0 { \u00a0 \u00a0 \u00a0 \u00a0 LOG(FATAL,&#034;socket create eror\\\\n&#034;); \u00a0 \u00a0 \u00a0 \u00a0 exit(SOCKET_ERROR); \u00a0 \u00a0 } \u00a0 \u00a0 LOG(INFO,&#034;socket create success,sockfd: %d\\\\n&#034;,_sockfd); \/\/ 3 \u00a0 \u00a0 \u00a0 struct sockaddr_in local; \u00a0 \u00a0 memset(&amp;local,0,sizeof(local)); \u00a0 \u00a0 local.sin_family &#061; AF_INET; \u00a0 \u00a0 local.sin_port &#061; htons(_port); \u00a0 \u00a0 local.sin_addr.s_addr &#061; INADDR_ANY; \u00a0 \u00a0 \u00a0 \/\/ 2.bind sockfd \u548c socket addr \u00a0 \u00a0 if(::bind(_sockfd,(struct sockaddr*)&amp;local,sizeof(local)) &lt; 0) \u00a0 \u00a0 { \u00a0 \u00a0 \u00a0 \u00a0 LOG(FATAL,&#034;bind eror\\\\n&#034;); \u00a0 \u00a0 \u00a0 \u00a0 exit(BIND_ERROR); \u00a0 \u00a0 } \u00a0 \u00a0 LOG(INFO,&#034;bind success\\\\n&#034;); \u00a0 \u00a0 \u00a0 \/\/ 3.\u56e0\u4e3atcp\u662f\u9762\u5411\u8fde\u63a5\u7684&#xff0c;tcp\u9700\u8981\u672a\u6765\u4e0d\u77ed\u5730\u83b7\u53d6\u8fde\u63a5 \u00a0 \u00a0 \/\/ \u8001\u677f\u6a21\u5f0f&#xff0c;\u968f\u65f6\u7b49\u5f85\u88ab\u8fde\u63a5 \u00a0 \u00a0 if(::listen(_sockfd,gblcklog) &lt; 0) \u00a0 \u00a0 { \u00a0 \u00a0 \u00a0 \u00a0 LOG(FATAL,&#034;listen eror\\\\n&#034;); \u00a0 \u00a0 \u00a0 \u00a0 exit(LISTEN_ERROR); \u00a0 \u00a0 } \u00a0 \u00a0 LOG(INFO,&#034;listen success\\\\n&#034;); }<\/p>\n<p>\u4e3a\u4e86\u6d4b\u8bd5\u8be5\u51fd\u6570&#xff0c;\u5148\u5c06Loop\u51fd\u6570\u8bbe\u8ba1\u6210\u6b7b\u5faa\u73af&#xff01;<\/p>\n<p>Loop()<\/p>\n<p>\/\/ \u6d4b\u8bd5 void Loop() { \u00a0 \u00a0 _isrunning &#061; true; \u00a0 \u00a0 while(_isrunning) \u00a0 \u00a0 { \u00a0 \u00a0 \u00a0 \u00a0 sleep(1); \u00a0 \u00a0 } \u00a0 \u00a0 _isrunning &#061; false; }<\/p>\n<p> 2.4\u3001Loop() Loop() \u51fd\u6570\u4e00\u76f4\u6267\u884c\u670d\u52a1&#xff01;<\/p>\n<p>\u6267\u884c\u670d\u52a1\u51fd\u6570\u4e3b\u8981\u5206\u4e3a\u4e24\u6b65&#xff1a;<\/p>\n<p>1\u3001\u83b7\u53d6\u65b0\u8fde\u63a5(accept\u51fd\u6570[\u4ece\u5df2\u5b8c\u6210\u8fde\u63a5\u961f\u5217\u7684\u5934\u90e8\u8fd4\u56de\u4e0b\u4e00\u4e2a\u5df2\u5b8c\u6210\u8fde\u63a5&#xff0c;\u5982\u679c\u961f\u5217\u4e3a\u7a7a&#xff0c;\u5219\u963b\u585e\u8c03\u7528\u8fdb\u7a0b]) accept()<\/p>\n<p>#include &lt;sys\/types.h&gt; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/* See NOTES *\/ #include &lt;sys\/socket.h&gt; \u00a0 int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen); \u00a0<\/p>\n<p>\u53c2\u6570<\/p>\n<p>sockfd&#xff1a;\u8fd9\u662f\u4e00\u4e2a\u76d1\u542c\u5957\u63a5\u5b57\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff0c;\u5b83\u5e94\u8be5\u662f\u4e00\u4e2a\u5df2\u7ecf\u901a\u8fc7 socket \u51fd\u6570\u521b\u5efa&#xff0c;\u5e76\u901a\u8fc7 bind \u51fd\u6570\u7ed1\u5b9a\u5230\u7279\u5b9a\u5730\u5740\u548c\u7aef\u53e3&#xff0c;\u4ee5\u53ca\u901a\u8fc7 listen \u51fd\u6570\u8bbe\u7f6e\u4e3a\u76d1\u542c\u6a21\u5f0f\u7684\u5957\u63a5\u5b57\u3002 addr&#xff1a;\u8fd9\u662f\u4e00\u4e2a\u6307\u5411 sockaddr \u7ed3\u6784\u7684\u6307\u9488&#xff0c;\u8be5\u7ed3\u6784\u7528\u4e8e\u5b58\u50a8\u63a5\u53d7\u8fde\u63a5\u7684\u5ba2\u6237\u7aef\u7684\u5730\u5740\u4fe1\u606f\u3002\u5982\u679c\u4e0d\u9700\u8981\u8fd9\u4e2a\u4fe1\u606f&#xff0c;\u53ef\u4ee5\u4f20\u9012 NULL\u3002 addrlen&#xff1a;\u8fd9\u662f\u4e00\u4e2a\u6307\u5411 socklen_t \u7c7b\u578b\u7684\u53d8\u91cf\u7684\u6307\u9488&#xff0c;\u7528\u4e8e\u5b58\u50a8 addr \u7ed3\u6784\u7684\u5927\u5c0f\u3002\u5728\u8c03\u7528 accept \u4e4b\u524d&#xff0c;\u5e94\u8be5\u5c06\u8be5\u53d8\u91cf\u7684\u503c\u8bbe\u7f6e\u4e3a addr \u7ed3\u6784\u7684\u5927\u5c0f\u3002\u5728\u8c03\u7528\u8fd4\u56de\u540e&#xff0c;\u8be5\u53d8\u91cf\u5c06\u5305\u542b\u5b9e\u9645\u8fd4\u56de\u7684\u5730\u5740\u4fe1\u606f\u7684\u957f\u5ea6\u3002\u5982\u679c addr \u662f NULL&#xff0c;\u5219\u8fd9\u4e2a\u53c2\u6570\u4e5f\u53ef\u4ee5\u662f NULL\u3002 \u8fd4\u56de\u503c<\/p>\n<p>\u6210\u529f\u65f6&#xff0c;accept \u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u5957\u63a5\u5b57\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff0c;\u7528\u4e8e\u4e0e\u63a5\u53d7\u7684\u8fde\u63a5\u8fdb\u884c\u901a\u4fe1\u3002\u8fd9\u4e2a\u65b0\u7684\u5957\u63a5\u5b57\u662f\u539f\u59cb\u76d1\u542c\u5957\u63a5\u5b57\u7684\u5b50\u5957\u63a5\u5b57&#xff0c;\u5b83\u7ee7\u627f\u4e86\u8bb8\u591a\u5c5e\u6027&#xff08;\u5982\u5957\u63a5\u5b57\u9009\u9879&#xff09;&#xff0c;\u4f46\u4e0e\u539f\u59cb\u5957\u63a5\u5b57\u662f\u72ec\u7acb\u7684\u3002 \u5931\u8d25\u65f6&#xff0c;\u8fd4\u56de -1&#xff0c;\u5e76\u8bbe\u7f6e errno \u4ee5\u6307\u793a\u9519\u8bef\u7c7b\u578b\u3002 \u56e0\u6b64TcpServer\u7c7b\u7684_sockfd\u5e94\u8be5\u6539\u4e3a_listensockfd&#xff01;&#xff01;&#xff01;<\/p>\n<p>TcpServer\u7c7b<\/p>\n<p>\/\/ \u9762\u5411\u5b57\u8282\u6d41 class TcpServer { public: \u00a0 \u00a0 TcpServer(uint16_t port &#061; gport):_port(port),_listensockfd(gsockfd),_isrunning(false) \u00a0 \u00a0 {} \u00a0 \u00a0\u00a0 \u00a0 \u00a0 void InitServer() \u00a0 \u00a0 { \u00a0 \u00a0 \u00a0 \u00a0 \/\/ 1.\u521b\u5efasocket \u00a0 \u00a0 \u00a0 \u00a0 _listensockfd &#061; ::socket(AF_INET,SOCK_STREAM,0); \u00a0 \u00a0 \u00a0 \u00a0 if(_listensockfd &lt; 0) \u00a0 \u00a0 \u00a0 \u00a0 { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 LOG(FATAL,&#034;socket create eror\\\\n&#034;); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 exit(SOCKET_ERROR); \u00a0 \u00a0 \u00a0 \u00a0 } \u00a0 \u00a0 \u00a0 \u00a0 LOG(INFO,&#034;socket create success,sockfd: %d\\\\n&#034;,_listensockfd); \/\/ 3 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 struct sockaddr_in local; \u00a0 \u00a0 \u00a0 \u00a0 memset(&amp;local,0,sizeof(local)); \u00a0 \u00a0 \u00a0 \u00a0 local.sin_family &#061; AF_INET; \u00a0 \u00a0 \u00a0 \u00a0 local.sin_port &#061; htons(_port); \u00a0 \u00a0 \u00a0 \u00a0 local.sin_addr.s_addr &#061; INADDR_ANY; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ 2.bind sockfd \u548c socket addr \u00a0 \u00a0 \u00a0 \u00a0 if(::bind(_listensockfd,(struct sockaddr*)&amp;local,sizeof(local)) &lt; 0) \u00a0 \u00a0 \u00a0 \u00a0 { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 LOG(FATAL,&#034;bind eror\\\\n&#034;); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 exit(BIND_ERROR); \u00a0 \u00a0 \u00a0 \u00a0 } \u00a0 \u00a0 \u00a0 \u00a0 LOG(INFO,&#034;bind success\\\\n&#034;); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ 3.\u56e0\u4e3atcp\u662f\u9762\u5411\u8fde\u63a5\u7684&#xff0c;tcp\u9700\u8981\u672a\u6765\u4e0d\u77ed\u5730\u83b7\u53d6\u8fde\u63a5 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u8001\u677f\u6a21\u5f0f&#xff0c;\u968f\u65f6\u7b49\u5f85\u88ab\u8fde\u63a5 \u00a0 \u00a0 \u00a0 \u00a0 if(::listen(_listensockfd,gblcklog) &lt; 0) \u00a0 \u00a0 \u00a0 \u00a0 { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 LOG(FATAL,&#034;listen eror\\\\n&#034;); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 exit(LISTEN_ERROR); \u00a0 \u00a0 \u00a0 \u00a0 } \u00a0 \u00a0 \u00a0 \u00a0 LOG(INFO,&#034;listen success\\\\n&#034;); \u00a0 \u00a0 } \u00a0 \u00a0 ~TcpServer() \u00a0 \u00a0 {} private: \u00a0 \u00a0 uint16_t _port; \u00a0 \u00a0 int _listensockfd; \u00a0 \u00a0 bool _isrunning; };<\/p>\n<p>2\u3001\u6267\u884c\u670d\u52a1(\u524d\u63d0\u662f\u83b7\u53d6\u5230\u65b0\u8fde\u63a5) \u6267\u884c\u670d\u52a1\u603b\u5171\u6709\u56db\u4e2a\u7248\u672c&#xff01;<\/p>\n<p>2.4.1\u3001Server 0(\u4e0d\u9760\u8c31\u7248\u672c) Server 0\u7248\u672c\u76f4\u63a5\u6267\u884c\u957f\u670d\u52a1&#xff01;<\/p>\n<p>Loop()<\/p>\n<p>Loop()\u51fd\u6570\u5148\u83b7\u53d6\u65b0\u8fde\u63a5&#xff0c;\u83b7\u53d6\u6210\u529f\u5219\u6267\u884c\u670d\u52a1\u51fd\u6570&#xff01;<\/p>\n<p>void Loop() { \u00a0 \u00a0 _isrunning &#061; true; \u00a0 \u00a0 while(_isrunning) \u00a0 \u00a0 { \u00a0 \u00a0 \u00a0 \u00a0 struct sockaddr_in client; \u00a0 \u00a0 \u00a0 \u00a0 socklen_t len &#061; sizeof(client); \u00a0 \u00a0 \u00a0 \u00a0 \/\/ 1.\u83b7\u53d6\u65b0\u8fde\u63a5 \u00a0 \u00a0 \u00a0 \u00a0 int sockfd &#061; ::accept(_listensockfd,(struct sockaddr*)&amp;client,&amp;len); \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u83b7\u53d6\u5931\u8d25\u7ee7\u7eed\u83b7\u53d6 \u00a0 \u00a0 \u00a0 \u00a0 if(sockfd &lt; 0) \u00a0 \u00a0 \u00a0 \u00a0 { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 LOG(WARNING,&#034;sccept reeor\\\\n&#034;); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 continue; \u00a0 \u00a0 \u00a0 \u00a0 } \u00a0 \u00a0 \u00a0 \u00a0 InetAddr addr(client); \u00a0 \u00a0 \u00a0 \u00a0 LOG(INFO,&#034;get a new link,client info: %s,sockfd:%d\\\\n&#034;,addr.AddrStr().c_str(),sockfd); \/\/ 4 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u83b7\u53d6\u6210\u529f \u00a0 \u00a0 \u00a0 \u00a0 \/\/ version 0 &#8212; \u4e0d\u9760\u8c31\u7248\u672c \u00a0 \u00a0 \u00a0 \u00a0 Server(sockfd,addr); \u00a0 \u00a0 } \u00a0 \u00a0 _isrunning &#061; false; }<\/p>\n<p>Server()<\/p>\n<p>\u6ce8\u610f&#xff1a;tcp\u534f\u8bae\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528read&#xff0c;write\u51fd\u6570\u8bfb\u5199\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u5185\u5bb9(\u56e0\u4e3atcp\u662f\u9762\u5411\u5b57\u8282\u6d41\u7684)&#xff01;<\/p>\n<p>Server()\u6267\u884c\u670d\u52a1&#xff0c;\u5148\u4ece\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e2d\u8bfb\u6570\u636e&#xff0c;\u518d\u5199\u6570\u636e\u5230\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e2d&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb774\u6b21\uff0c\u70b9\u8d5e8\u6b21\uff0c\u6536\u85cf10\u6b21\u3002sockfd\uff1a\u8fd9\u662f\u4e00\u4e2a\u76d1\u542c\u5957\u63a5\u5b57\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u5b83\u5e94\u8be5\u662f\u4e00\u4e2a\u5df2\u7ecf\u901a\u8fc7 socket \u51fd\u6570\u521b\u5efa\uff0c\u5e76\u901a\u8fc7 bind \u51fd\u6570\u7ed1\u5b9a\u5230\u7279\u5b9a\u5730\u5740\u548c\u7aef\u53e3\uff0c\u4ee5\u53ca\u901a\u8fc7 listen \u51fd\u6570\u8bbe\u7f6e\u4e3a\u76d1\u542c\u6a21\u5f0f\u7684\u5957\u63a5\u5b57\u3002\u8fd9\u4e2a\u65b0\u7684\u5957\u63a5\u5b57\u662f\u539f\u59cb\u76d1\u542c\u5957\u63a5\u5b57\u7684\u5b50\u5957\u63a5\u5b57\uff0c\u5b83\u7ee7\u627f\u4e86\u8bb8\u591a\u5c5e\u6027\uff08\u5982\u5957\u63a5\u5b57\u9009\u9879\uff09\uff0c\u4f46\u4e0e\u539f\u59cb\u5957\u63a5\u5b57\u662f\u72ec\u7acb\u7684\u3002\u524d\u9762\u51e0\u5f39\u4f7f\u7528UDP\u534f\u8bae\u5b9e\u73b0\u4e86\u76f8\u5173\u529f\u80fd\uff0c\u6b64\u5f39\u4f7f\u7528TCP\u534f\u8bae\u5b9e\u73b0\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u7aef\u7684\u901a\u4fe1\uff0c\u76f8\u6bd4\u4e0eUDP\u534f\u8bae\uff0cTCP\u534f\u8bae\u66f4\u52a0\u53ef\u9760\uff0c\u4e5f\u66f4\u52a0\u590d\u6742\uff01sockfd\uff1a\u8fd9\u662f\u4e00\u4e2a\u5df2\u521b\u5efa\u7684\u5957\u63a5\u5b57\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u5b83\u5e94\u8be5\u662f\u4e00\u4e2a\u7ed1\u5b9a\u5230\u67d0\u4e2a\u5730\u5740\u548c\u7aef\u53e3\u7684\u5957\u63a5\u5b57\u3002<\/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":[205,270,43],"topic":[],"class_list":["post-34020","post","type-post","status-publish","format-standard","hentry","category-server","tag-tcp-ip","tag-270","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u6784\u5efaTCP\u670d\u52a1\u5668\uff1a\u4ece\u57fa\u7840\u5230\u7ebf\u7a0b\u6c60\u7248\u672c\u7684\u5b9e\u73b0\u4e0e\u6d4b\u8bd5\u8be6\u89e3 - \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\/34020.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u6784\u5efaTCP\u670d\u52a1\u5668\uff1a\u4ece\u57fa\u7840\u5230\u7ebf\u7a0b\u6c60\u7248\u672c\u7684\u5b9e\u73b0\u4e0e\u6d4b\u8bd5\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb774\u6b21\uff0c\u70b9\u8d5e8\u6b21\uff0c\u6536\u85cf10\u6b21\u3002sockfd\uff1a\u8fd9\u662f\u4e00\u4e2a\u76d1\u542c\u5957\u63a5\u5b57\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u5b83\u5e94\u8be5\u662f\u4e00\u4e2a\u5df2\u7ecf\u901a\u8fc7 socket \u51fd\u6570\u521b\u5efa\uff0c\u5e76\u901a\u8fc7 bind \u51fd\u6570\u7ed1\u5b9a\u5230\u7279\u5b9a\u5730\u5740\u548c\u7aef\u53e3\uff0c\u4ee5\u53ca\u901a\u8fc7 listen \u51fd\u6570\u8bbe\u7f6e\u4e3a\u76d1\u542c\u6a21\u5f0f\u7684\u5957\u63a5\u5b57\u3002\u8fd9\u4e2a\u65b0\u7684\u5957\u63a5\u5b57\u662f\u539f\u59cb\u76d1\u542c\u5957\u63a5\u5b57\u7684\u5b50\u5957\u63a5\u5b57\uff0c\u5b83\u7ee7\u627f\u4e86\u8bb8\u591a\u5c5e\u6027\uff08\u5982\u5957\u63a5\u5b57\u9009\u9879\uff09\uff0c\u4f46\u4e0e\u539f\u59cb\u5957\u63a5\u5b57\u662f\u72ec\u7acb\u7684\u3002\u524d\u9762\u51e0\u5f39\u4f7f\u7528UDP\u534f\u8bae\u5b9e\u73b0\u4e86\u76f8\u5173\u529f\u80fd\uff0c\u6b64\u5f39\u4f7f\u7528TCP\u534f\u8bae\u5b9e\u73b0\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u7aef\u7684\u901a\u4fe1\uff0c\u76f8\u6bd4\u4e0eUDP\u534f\u8bae\uff0cTCP\u534f\u8bae\u66f4\u52a0\u53ef\u9760\uff0c\u4e5f\u66f4\u52a0\u590d\u6742\uff01sockfd\uff1a\u8fd9\u662f\u4e00\u4e2a\u5df2\u521b\u5efa\u7684\u5957\u63a5\u5b57\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u5b83\u5e94\u8be5\u662f\u4e00\u4e2a\u7ed1\u5b9a\u5230\u67d0\u4e2a\u5730\u5740\u548c\u7aef\u53e3\u7684\u5957\u63a5\u5b57\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/34020.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-28T14:15:38+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\/34020.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/34020.html\",\"name\":\"\u6784\u5efaTCP\u670d\u52a1\u5668\uff1a\u4ece\u57fa\u7840\u5230\u7ebf\u7a0b\u6c60\u7248\u672c\u7684\u5b9e\u73b0\u4e0e\u6d4b\u8bd5\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-28T14:15:38+00:00\",\"dateModified\":\"2025-04-28T14:15:38+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/34020.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/34020.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/34020.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u6784\u5efaTCP\u670d\u52a1\u5668\uff1a\u4ece\u57fa\u7840\u5230\u7ebf\u7a0b\u6c60\u7248\u672c\u7684\u5b9e\u73b0\u4e0e\u6d4b\u8bd5\u8be6\u89e3\"}]},{\"@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":"\u6784\u5efaTCP\u670d\u52a1\u5668\uff1a\u4ece\u57fa\u7840\u5230\u7ebf\u7a0b\u6c60\u7248\u672c\u7684\u5b9e\u73b0\u4e0e\u6d4b\u8bd5\u8be6\u89e3 - \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\/34020.html","og_locale":"zh_CN","og_type":"article","og_title":"\u6784\u5efaTCP\u670d\u52a1\u5668\uff1a\u4ece\u57fa\u7840\u5230\u7ebf\u7a0b\u6c60\u7248\u672c\u7684\u5b9e\u73b0\u4e0e\u6d4b\u8bd5\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb774\u6b21\uff0c\u70b9\u8d5e8\u6b21\uff0c\u6536\u85cf10\u6b21\u3002sockfd\uff1a\u8fd9\u662f\u4e00\u4e2a\u76d1\u542c\u5957\u63a5\u5b57\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u5b83\u5e94\u8be5\u662f\u4e00\u4e2a\u5df2\u7ecf\u901a\u8fc7 socket \u51fd\u6570\u521b\u5efa\uff0c\u5e76\u901a\u8fc7 bind \u51fd\u6570\u7ed1\u5b9a\u5230\u7279\u5b9a\u5730\u5740\u548c\u7aef\u53e3\uff0c\u4ee5\u53ca\u901a\u8fc7 listen \u51fd\u6570\u8bbe\u7f6e\u4e3a\u76d1\u542c\u6a21\u5f0f\u7684\u5957\u63a5\u5b57\u3002\u8fd9\u4e2a\u65b0\u7684\u5957\u63a5\u5b57\u662f\u539f\u59cb\u76d1\u542c\u5957\u63a5\u5b57\u7684\u5b50\u5957\u63a5\u5b57\uff0c\u5b83\u7ee7\u627f\u4e86\u8bb8\u591a\u5c5e\u6027\uff08\u5982\u5957\u63a5\u5b57\u9009\u9879\uff09\uff0c\u4f46\u4e0e\u539f\u59cb\u5957\u63a5\u5b57\u662f\u72ec\u7acb\u7684\u3002\u524d\u9762\u51e0\u5f39\u4f7f\u7528UDP\u534f\u8bae\u5b9e\u73b0\u4e86\u76f8\u5173\u529f\u80fd\uff0c\u6b64\u5f39\u4f7f\u7528TCP\u534f\u8bae\u5b9e\u73b0\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u7aef\u7684\u901a\u4fe1\uff0c\u76f8\u6bd4\u4e0eUDP\u534f\u8bae\uff0cTCP\u534f\u8bae\u66f4\u52a0\u53ef\u9760\uff0c\u4e5f\u66f4\u52a0\u590d\u6742\uff01sockfd\uff1a\u8fd9\u662f\u4e00\u4e2a\u5df2\u521b\u5efa\u7684\u5957\u63a5\u5b57\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u5b83\u5e94\u8be5\u662f\u4e00\u4e2a\u7ed1\u5b9a\u5230\u67d0\u4e2a\u5730\u5740\u548c\u7aef\u53e3\u7684\u5957\u63a5\u5b57\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/34020.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-28T14:15:38+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\/34020.html","url":"https:\/\/www.wsisp.com\/helps\/34020.html","name":"\u6784\u5efaTCP\u670d\u52a1\u5668\uff1a\u4ece\u57fa\u7840\u5230\u7ebf\u7a0b\u6c60\u7248\u672c\u7684\u5b9e\u73b0\u4e0e\u6d4b\u8bd5\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-28T14:15:38+00:00","dateModified":"2025-04-28T14:15:38+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/34020.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/34020.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/34020.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u6784\u5efaTCP\u670d\u52a1\u5668\uff1a\u4ece\u57fa\u7840\u5230\u7ebf\u7a0b\u6c60\u7248\u672c\u7684\u5b9e\u73b0\u4e0e\u6d4b\u8bd5\u8be6\u89e3"}]},{"@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\/34020","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=34020"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/34020\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=34020"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=34020"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=34020"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=34020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}