{"id":10597,"date":"2025-04-18T18:07:16","date_gmt":"2025-04-18T10:07:16","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/10597.html"},"modified":"2025-04-18T18:07:16","modified_gmt":"2025-04-18T10:07:16","slug":"%e3%80%90%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b%e3%80%91%e9%ab%98%e6%80%a7%e8%83%bd%e5%b9%b6%e5%8f%91%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%ba%90%e7%a0%81%e5%89%96%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/10597.html","title":{"rendered":"\u3010\u7f51\u7edc\u7f16\u7a0b\u3011\u9ad8\u6027\u80fd\u5e76\u53d1\u670d\u52a1\u5668\u6e90\u7801\u5256\u6790"},"content":{"rendered":"<p>\u00a0<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"23\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418100714-68022452cd1c8.png\" width=\"23\" \/><\/p>\n<p>hello &#xff01;\u5927\u5bb6\u597d\u5440&#xff01; \u6b22\u8fce\u5927\u5bb6\u6765\u5230\u6211\u7684\u7f51\u7edc\u7f16\u7a0b\u7cfb\u5217\u4e4b\u6d2a\u6c34\u7f51\u7edc\u653b\u51fb&#xff0c;\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d&#xff0c;\u4f60\u5c06\u4f1a\u5b66\u4e60\u5230\u5728\u7f51\u7edc\u7f16\u7a0b\u4e2d\u5982\u4f55\u642d\u5efa\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684\u5e76\u53d1\u670d\u52a1\u5668&#xff0c;\u5e76\u4e14\u6211\u4f1a\u7ed9\u51fa\u6e90\u7801\u8fdb\u884c\u5256\u6790&#xff0c;\u4ee5\u53ca\u624b\u7ed8UML\u56fe\u6765\u5e2e\u52a9\u5927\u5bb6\u6765\u7406\u89e3&#xff0c;\u5e0c\u671b\u80fd\u8ba9\u5927\u5bb6\u66f4\u80fd\u4e86\u89e3\u7f51\u7edc\u7f16\u7a0b\u6280\u672f&#xff01;&#xff01;&#xff01;<\/p>\n<p>\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"23\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418100714-68022452d5880.png\" width=\"23\" \/>&#xff0c;\u5927\u5bb6\u8981\u662f\u89c9\u5f97\u6211\u5199\u7684\u4e0d\u9519\u7684\u8bdd&#xff0c;\u90a3\u5c31\u70b9\u70b9\u514d\u8d39\u7684\u5c0f\u7231\u5fc3\u5427&#xff01;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"28\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418100714-68022452dd317.png\" width=\"28\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"100\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418100714-68022452e4e20.gif\" width=\"100\" \/>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/p>\n<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E4%B8%80.%E7%BD%91%E7%BB%9C%E6%9C%8D%E5%8A%A1%E5%99%A8%C2%A0-toc\" style=\"margin-left:0px\">\u4e00.\u7f51\u7edc\u670d\u52a1\u5668\u00a0<\/p>\n<p id=\"%C2%A01.1%20%E6%99%AE%E9%80%9A%E5%BE%AA%E7%8E%AF%E7%BD%91%E7%BB%9C%E6%9C%8D%E5%8A%A1%E5%99%A8-toc\" style=\"margin-left:40px\">\u00a01.1 \u666e\u901a\u5faa\u73af\u7f51\u7edc\u670d\u52a1\u5668<\/p>\n<p id=\"-toc\" style=\"margin-left:40px\">\n<p id=\"2.2%20%E7%AE%80%E5%8D%95%E5%B9%B6%E5%8F%91%E7%BD%91%E7%BB%9C%E6%9C%8D%E5%8A%A1%E5%99%A8-toc\" style=\"margin-left:40px\">2.2 \u7b80\u5355\u5e76\u53d1\u7f51\u7edc\u670d\u52a1\u5668<\/p>\n<p id=\"2.2.1%E7%AE%80%E5%8D%95%E7%9A%84%E5%B9%B6%E5%8F%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%A8%A1%E5%9E%8B-toc\" style=\"margin-left:80px\">2.2.1\u7b80\u5355\u7684\u5e76\u53d1\u670d\u52a1\u5668\u6a21\u578b<\/p>\n<p id=\"2.2.2%E4%BD%BF%E7%94%A8%E8%BF%9B%E7%A8%8B%E7%9A%84%E5%B9%B6%E5%8F%91%E6%9C%8D%E5%8A%A1%E5%99%A8-toc\" style=\"margin-left:80px\">2.2.2\u4f7f\u7528\u8fdb\u7a0b\u7684\u5e76\u53d1\u670d\u52a1\u5668<\/p>\n<p id=\"2.2.3%E4%BD%BF%E7%94%A8%E7%BA%BF%E7%A8%8B%E7%9A%84%E5%B9%B6%E5%8F%91%E6%9C%8D%E5%8A%A1%E5%99%A8-toc\" style=\"margin-left:80px\">2.2.3\u4f7f\u7528\u7ebf\u7a0b\u7684\u5e76\u53d1\u670d\u52a1\u5668<\/p>\n<p id=\"2.2.4%E5%85%B6%E4%BB%96%E5%B9%B6%E5%8F%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%A8%A1%E5%9E%8B-toc\" style=\"margin-left:80px\">2.2.4\u5176\u4ed6\u5e76\u53d1\u670d\u52a1\u5668\u6a21\u578b<\/p>\n<p id=\"%E4%BA%8C.%E4%BD%BF%E7%94%A8%E4%BA%92%E6%96%A5%E9%94%81%E5%AE%9E%E7%8E%B0%E5%8D%95%E7%BA%BF%E7%A8%8B%E5%A4%84%E7%90%86%E5%8D%95%E4%B8%AA%E5%AE%A2%E6%88%B7-toc\" style=\"margin-left:0px\">\u4e8c.\u4f7f\u7528\u4e92\u65a5\u9501\u5b9e\u73b0\u5355\u7ebf\u7a0b\u5904\u7406\u5355\u4e2a\u5ba2\u6237<\/p>\n<p id=\"2.1%20%E5%85%B7%E4%BD%93%E6%AD%A5%E9%AA%A4-toc\" style=\"margin-left:40px\">2.1 \u5177\u4f53\u6b65\u9aa4<\/p>\n<p id=\"2.2%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%BB%A3%E7%A0%81%E6%A8%A1%E6%9D%BF-toc\" style=\"margin-left:40px\">2.2\u670d\u52a1\u5668\u4ee3\u7801\u6a21\u677f<\/p>\n<p id=\"%E4%B8%89.%E6%BA%90%E7%A0%81%E5%89%96%E6%9E%90-toc\" style=\"margin-left:0px\">\u4e09.\u6e90\u7801\u5256\u6790<\/p>\n<hr id=\"hr-toc\" \/>\n<h2 id=\"%E4%B8%80.%E7%BD%91%E7%BB%9C%E6%9C%8D%E5%8A%A1%E5%99%A8%C2%A0\">\u4e00.\u7f51\u7edc\u670d\u52a1\u5668\u00a0<\/h2>\n<h3 id=\"%C2%A01.1%20%E6%99%AE%E9%80%9A%E5%BE%AA%E7%8E%AF%E7%BD%91%E7%BB%9C%E6%9C%8D%E5%8A%A1%E5%99%A8\">\u00a01.1 \u666e\u901a\u5faa\u73af\u7f51\u7edc\u670d\u52a1\u5668<\/h3>\n<p>\u5bf9\u4e8e\u666e\u901a\u7684\u5faa\u73af\u7f51\u7edc\u670d\u52a1\u5668&#xff0c;\u5176\u5b9e\u5c31\u662f\u670d\u52a1\u5668\u4f7f\u7528\u5faa\u73af\u7684\u65b9\u6cd5\u9010\u4e2a\u5bf9\u5ba2\u6237\u7684\u8fde\u63a5\u8fdb\u884c\u5904\u7406&#xff0c;\u5904\u7406\u5b8c\u4e00\u4e2a\u8fde\u63a5\u540e\u518d\u5904\u7406\u4e0b\u4e00\u4e2a\u8fde\u63a5&#xff0c;\u5176\u8fc7\u7a0b\u5982\u4e0b&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"563\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418100714-68022452f2868.png\" width=\"723\" \/><\/p>\n<p>\u6700\u7b80\u5355\u7684\u4ee3\u7801\u6a21\u578b\u6211\u8fd8\u662f\u7ed9\u5927\u5bb6&#xff1a;<\/p>\n<p>#include&lt;t_stdio.h&gt;<br \/>\n#include&lt;sys\/types.h&gt;<br \/>\n#include &lt;sys\/socket.h&gt;<br \/>\n#include&lt;arpa\/inet.h&gt;<br \/>\n#include &lt;sys\/socket.h&gt;<br \/>\n#include&lt;ctype.h&gt;<br \/>\n#include&lt;unistd.h&gt;<br \/>\nint main(void){<br \/>\n    struct sockaddr_in serv,cli;<br \/>\n    socklen_t cli_len;<br \/>\n    char buf[128];<br \/>\n    char IP[32];<br \/>\n    \/\/\u521b\u5efa\u4e00\u4e2a\u901a\u8baf\u7aef\u70b9&#xff0c;\u8fd4\u56de\u8be5\u7aef\u70b9\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26<br \/>\n    \/\/\u521b\u5efa\u4e00\u4e2aipv4\u7684tcp\u8fde\u63a5\u7aef\u53e3<br \/>\n    int s_fd&#061;socket( AF_INET ,SOCK_STREAM ,0);<\/p>\n<p>    \/\/\u9700\u8981\u5bf9server\u53d8\u91cf\u6210\u5458\u521d\u59cb\u5316<br \/>\n    serv.sin_family&#061;AF_INET;<br \/>\n    serv.sin_port&#061;htons(5556);<br \/>\n    serv.sin_addr.s_addr&#061;htonl(INADDR_ANY);<br \/>\n    \/\/\u5c06s_fd\u548c\u672c\u5730\u5730\u5740&#xff0c;\u7aef\u53e3\u53f7\u7ed1\u5b9a<br \/>\n    int b&#061;bind(s_fd,(struct sockaddr *)&amp;serv,sizeof(serv));<\/p>\n<p>    if(b&#061;&#061;-1)E_MSG(&#034;bind&#034;,-1);<br \/>\n    if(s_fd&#061;&#061;-1)E_MSG(&#034;socket&#034;,-1);<br \/>\n    \/\/\u5c06s_fd\u8bbe\u7f6e\u4e3a\u88ab\u52a8\u8fde\u63a5&#xff0c;\u76d1\u542c\u5ba2\u6237\u7aef\u8fde\u63a5\u7684\u5230\u6765<br \/>\n    \/\/\u5c06\u5ba2\u6237\u7aef\u5230\u6765\u7684\u8fde\u63a5\u653e\u5165\u672a\u51b3\u8fde\u63a5\u961f\u5217\u4e2d<br \/>\n    \/\/\u6307\u5b9a\u672a\u51b3\u8fde\u63a5\u961f\u5217\u7684\u957f\u5ea6<br \/>\n    listen(s_fd,5);<br \/>\n    while(1){<br \/>\n        \/\/\u4eces_fd\u8bbe\u5907\u7684\u672a\u8fde\u63a5\u961f\u5217\u4e2d\u63d0\u53d6\u4e00\u4e2a\u8fdb\u7a0b\u8fdb\u884c\u5904\u7406<br \/>\n        \/\/\u8fd4\u56de\u4e00\u4e2a\u8fde\u63a5\u63cf\u8ff0\u7b26&#xff0c;\u4f7f\u7528\u8fd9\u4e2a\u8fde\u63a5\u63cf\u8ff0\u7b26\u4e0e\u5ba2\u6237\u7aef\u8fdb\u884c\u901a\u8baf<br \/>\n        int c_fd&#061;accept(s_fd,(struct sockaddr *)&amp;cli,&amp;cli_len);<br \/>\n        if(c_fd&#061;&#061;-1)E_MSG(&#034;accept&#034;,-1);<br \/>\n        \/\/binary&#8212;&gt;text<br \/>\n        inet_ntop(AF_INET,&amp;cli.sin_addr,IP,32);<br \/>\n        printf(&#034;client ip: %s\\\\n&#034;,IP);<br \/>\n        \/\/\u4ee3\u7801\u6267\u884c\u5230\u8fd9\u91cc&#xff0c;\u4e09\u6b21\u63e1\u624b\u4ee5\u53ca\u5b8c\u6210&#xff0c;\u53ef\u4ee5\u8fdb\u884c\u6570\u636e\u4f20\u8f93\u4e86<br \/>\n        \/\/\u4ecec_fd\u4e2d\u8bfb\u53d6\u5ba2\u6237\u7aef\u53d1\u9001\u8fc7\u6765\u7684\u8bf7\u6c42\u4fe1\u606f<br \/>\n        int r &#061; read(c_fd,buf,128);<br \/>\n        \/\/\u5904\u7406\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\u4fe1\u606f<br \/>\n        int i;<br \/>\n         for(i&#061;0;i&lt;r;i&#043;&#043;){<br \/>\n            buf[i]&#061;toupper(buf[i]);<br \/>\n         }<br \/>\n         \/\/\u5c06\u5904\u7406\u7ed3\u679c\u56de\u9001\u5ba2\u6237\u7aef<br \/>\n         write(c_fd,buf,r);<br \/>\n        \/\/\u5173\u95ed\u672c\u6b21\u8fde\u63a5<br \/>\n        close(c_fd);<br \/>\n    }<\/p>\n<p>    return 0;<br \/>\n} <\/p>\n<p>\u8fd9\u662f\u6700\u7b80\u5355\u7684\u5faa\u73af\u670d\u52a1\u5668\u4ee3\u7801&#xff0c;\u529f\u80fd\u662f\u5c06\u5ba2\u6237\u4f20\u8fc7\u6765\u7684\u5b57\u7b26\u4e32\u5168\u90e8\u8f6c\u6362\u4e3a\u5927\u5199&#xff0c;\u8fd9\u4e2a\u6700\u7b80\u5355\u4ee3\u7801\u5e0c\u671b\u5927\u5bb6\u80fd\u5168\u90e8\u5f04\u61c2&#xff0c;\u5173\u4e8e\u91cc\u9762\u8fd8\u6709\u4e0d\u61c2\u7684&#xff0c;\u53ef\u4ee5\u53bb\u770b\u6211\u6211\u524d\u9762\u7684\u535a\u5ba2&#xff1a;[C&#043;&#043;\/Linux] socket\u5957\u63a5\u5b57\u51fd\u6570-CSDN\u535a\u5ba2<\/p>\n<h3><\/h3>\n<h3 id=\"2.2%20%E7%AE%80%E5%8D%95%E5%B9%B6%E5%8F%91%E7%BD%91%E7%BB%9C%E6%9C%8D%E5%8A%A1%E5%99%A8\">2.2 \u7b80\u5355\u5e76\u53d1\u7f51\u7edc\u670d\u52a1\u5668<\/h3>\n<p>\u5e76\u53d1\u7f51\u7edc\u670d\u52a1\u5668\u662f\u6307\u80fd\u591f\u540c\u65f6\u5904\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u8bf7\u6c42\u7684\u7f51\u7edc\u670d\u52a1\u5668\u3002\u8fd9\u79cd\u670d\u52a1\u5668\u7684\u8bbe\u8ba1\u5141\u8bb8\u5b83\u5728\u4efb\u4f55\u65f6\u523b\u5904\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u548c\u8bf7\u6c42&#xff0c;\u800c\u4e0d\u4f1a\u56e0\u4e3a\u67d0\u4e2a\u8bf7\u6c42\u7684\u5904\u7406\u800c\u963b\u585e\u5176\u4ed6\u8bf7\u6c42\u3002\u5e76\u53d1\u670d\u52a1\u5668\u53ef\u4ee5\u63d0\u9ad8\u8d44\u6e90\u7684\u5229\u7528\u7387&#xff0c;\u589e\u5f3a\u670d\u52a1\u5668\u7684\u54cd\u5e94\u80fd\u529b&#xff0c;\u662f\u73b0\u4ee3\u7f51\u7edc\u5e94\u7528\u7684\u57fa\u7840\u3002\u4e0b\u9762\u6211\u5c06\u4ecb\u7ecd\u51e0\u79cd\u5e38\u89c1\u7684\u5e76\u53d1\u7f51\u7edc\u670d\u52a1\u5668\u6a21\u578b&#xff1a;<\/p>\n<h4 id=\"2.2.1%E7%AE%80%E5%8D%95%E7%9A%84%E5%B9%B6%E5%8F%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%A8%A1%E5%9E%8B\">2.2.1\u7b80\u5355\u7684\u5e76\u53d1\u670d\u52a1\u5668\u6a21\u578b<\/h4>\n<li>\n<p>\u8fed\u4ee3\u670d\u52a1\u5668&#xff08;Iterative Server&#xff09;&#xff1a;\u00a0\u8fd9\u79cd\u670d\u52a1\u5668\u4e00\u6b21\u5904\u7406\u4e00\u4e2a\u8bf7\u6c42\u3002\u5b83\u63a5\u6536\u4e00\u4e2a\u8bf7\u6c42&#xff0c;\u5904\u7406\u5b8c\u8be5\u8bf7\u6c42&#xff0c;\u7136\u540e\u624d\u63a5\u6536\u4e0b\u4e00\u4e2a\u8bf7\u6c42\u3002\u8fd9\u79cd\u6a21\u578b\u7b80\u5355&#xff0c;\u4f46\u6548\u7387\u4f4e\u4e0b&#xff0c;\u56e0\u4e3a\u5b83\u5728\u5904\u7406\u4e00\u4e2a\u8bf7\u6c42\u65f6\u4e0d\u80fd\u5904\u7406\u5176\u4ed6\u8bf7\u6c42\u3002<\/p>\n<\/li>\n<li>\n<p>\u5e76\u53d1\u670d\u52a1\u5668&#xff08;Concurrent Server&#xff09;&#xff1a;\u00a0\u5e76\u53d1\u670d\u52a1\u5668\u53ef\u4ee5\u540c\u65f6\u5904\u7406\u591a\u4e2a\u8bf7\u6c42\u3002\u8fd9\u901a\u5e38\u901a\u8fc7\u591a\u8fdb\u7a0b\u6216\u591a\u7ebf\u7a0b\u6765\u5b9e\u73b0\u3002\u670d\u52a1\u5668\u7684\u4e3b\u8fdb\u7a0b\u6216\u7ebf\u7a0b\u76d1\u542c\u7aef\u53e3&#xff0c;\u63a5\u53d7\u65b0\u7684\u8fde\u63a5&#xff0c;\u7136\u540e\u4e3a\u6bcf\u4e2a\u8fde\u63a5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u8fdb\u7a0b\u6216\u7ebf\u7a0b\u6765\u5904\u7406\u8bf7\u6c42\u3002<\/p>\n<\/li>\n<h4 id=\"2.2.2%E4%BD%BF%E7%94%A8%E8%BF%9B%E7%A8%8B%E7%9A%84%E5%B9%B6%E5%8F%91%E6%9C%8D%E5%8A%A1%E5%99%A8\">2.2.2\u4f7f\u7528\u8fdb\u7a0b\u7684\u5e76\u53d1\u670d\u52a1\u5668<\/h4>\n<li>\n<p>\u591a\u8fdb\u7a0b\u670d\u52a1\u5668&#xff08;Multiprocess Server&#xff09;&#xff1a;\u00a0\u5728\u8fd9\u4e2a\u6a21\u578b\u4e2d&#xff0c;\u670d\u52a1\u5668\u7684\u4e3b\u8fdb\u7a0b\u76d1\u542c\u7aef\u53e3&#xff0c;\u63a5\u53d7\u65b0\u7684\u8fde\u63a5\u3002\u6bcf\u5f53\u6709\u4e00\u4e2a\u65b0\u7684\u8fde\u63a5\u65f6&#xff0c;\u4e3b\u8fdb\u7a0b\u5c31fork\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u6765\u5904\u7406\u8fd9\u4e2a\u8fde\u63a5\u3002\u6bcf\u4e2a\u5b50\u8fdb\u7a0b\u90fd\u53ef\u4ee5\u72ec\u7acb\u5730\u4e0e\u5ba2\u6237\u7aef\u901a\u4fe1&#xff0c;\u5904\u7406\u8bf7\u6c42\u3002\u8fd9\u79cd\u6a21\u578b\u7684\u4f18\u70b9\u662f\u4ee3\u7801\u7b80\u5355&#xff0c;\u7f3a\u70b9\u662f\u8fdb\u7a0b\u521b\u5efa\u548c\u9500\u6bc1\u7684\u5f00\u9500\u8f83\u5927\u3002<\/p>\n<\/li>\n<li>\n<p>\u9884\u6d3e\u751f\u5b50\u8fdb\u7a0b\u670d\u52a1\u5668&#xff08;Pre-forking Server&#xff09;&#xff1a;\u00a0\u8fd9\u79cd\u670d\u52a1\u5668\u5728\u542f\u52a8\u65f6\u5c31\u9884\u5148\u521b\u5efa\u4e00\u5b9a\u6570\u91cf\u7684\u5b50\u8fdb\u7a0b&#xff0c;\u6bcf\u4e2a\u5b50\u8fdb\u7a0b\u90fd\u963b\u585e\u5728accept\u8c03\u7528\u4e0a\u7b49\u5f85\u65b0\u7684\u8fde\u63a5\u3002\u5f53\u4e00\u4e2a\u8fde\u63a5\u5230\u8fbe\u65f6&#xff0c;\u5176\u4e2d\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u63a5\u53d7\u8fde\u63a5\u5e76\u5904\u7406\u8bf7\u6c42\u3002\u8fd9\u79cd\u6a21\u578b\u51cf\u5c11\u4e86\u8fdb\u7a0b\u521b\u5efa\u7684\u5f00\u9500&#xff0c;\u4f46\u9700\u8981\u9884\u5148\u5206\u914d\u8d44\u6e90\u3002<\/p>\n<\/li>\n<p>\u8fd9\u91cc\u6211\u624b\u7ed8\u4e00\u4e2aUML\u56fe\u6765\u5e2e\u52a9\u5927\u5bb6\u7406\u89e3\u5982\u4f55\u5229\u7528\u8fdb\u7a0b\u6c60&#xff1a;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"617\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418100715-6802245318d2b.png\" width=\"1082\" \/><\/p>\n<h4 id=\"2.2.3%E4%BD%BF%E7%94%A8%E7%BA%BF%E7%A8%8B%E7%9A%84%E5%B9%B6%E5%8F%91%E6%9C%8D%E5%8A%A1%E5%99%A8\">2.2.3\u4f7f\u7528\u7ebf\u7a0b\u7684\u5e76\u53d1\u670d\u52a1\u5668<\/h4>\n<li>\n<p>\u591a\u7ebf\u7a0b\u670d\u52a1\u5668&#xff08;Multithreaded Server&#xff09;&#xff1a;\u00a0\u5728\u8fd9\u4e2a\u6a21\u578b\u4e2d&#xff0c;\u670d\u52a1\u5668\u7684\u4e3b\u7ebf\u7a0b\u76d1\u542c\u7aef\u53e3&#xff0c;\u63a5\u53d7\u65b0\u7684\u8fde\u63a5\u3002\u6bcf\u5f53\u6709\u4e00\u4e2a\u65b0\u7684\u8fde\u63a5\u65f6&#xff0c;\u4e3b\u7ebf\u7a0b\u5c31\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u7ebf\u7a0b\u6765\u5904\u7406\u8fd9\u4e2a\u8fde\u63a5\u3002\u7531\u4e8e\u7ebf\u7a0b\u5171\u4eab\u5185\u5b58\u7a7a\u95f4&#xff0c;\u56e0\u6b64\u5b83\u4eec\u4e4b\u95f4\u53ef\u4ee5\u66f4\u5bb9\u6613\u5730\u5171\u4eab\u6570\u636e&#xff0c;\u4f46\u8fd9\u4e5f\u5e26\u6765\u4e86\u540c\u6b65\u95ee\u9898\u3002<\/p>\n<\/li>\n<li>\n<p>\u7ebf\u7a0b\u6c60\u670d\u52a1\u5668&#xff08;Thread Pool Server&#xff09;&#xff1a;\u00a0\u7ebf\u7a0b\u6c60\u670d\u52a1\u5668\u9884\u5148\u521b\u5efa\u4e00\u5b9a\u6570\u91cf\u7684\u5de5\u4f5c\u7ebf\u7a0b&#xff0c;\u8fd9\u4e9b\u7ebf\u7a0b\u90fd\u963b\u585e\u5728\u7b49\u5f85\u4efb\u52a1\u961f\u5217\u4e0a\u3002\u5f53\u4e00\u4e2a\u65b0\u7684\u8fde\u63a5\u5230\u8fbe\u65f6&#xff0c;\u4e3b\u7ebf\u7a0b\u5c06\u8fde\u63a5\u653e\u5165\u4efb\u52a1\u961f\u5217&#xff0c;\u5de5\u4f5c\u7ebf\u7a0b\u4ece\u961f\u5217\u4e2d\u53d6\u51fa\u8fde\u63a5\u5e76\u5904\u7406\u8bf7\u6c42\u3002\u8fd9\u79cd\u6a21\u578b\u53ef\u4ee5\u9650\u5236\u7ebf\u7a0b\u7684\u6570\u91cf&#xff0c;\u51cf\u5c11\u7ebf\u7a0b\u521b\u5efa\u548c\u9500\u6bc1\u7684\u5f00\u9500\u3002<\/p>\n<\/li>\n<p>\u8fd9\u91cc\u6211\u624b\u7ed8\u4e00\u4e2aUML\u56fe\u6765\u5e2e\u52a9\u5927\u5bb6\u7406\u89e3\u5982\u4f55\u5229\u7528\u7ebf\u7a0b\u6c60&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"701\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418100715-68022453613ec.png\" width=\"1072\" \/><\/p>\n<\/p>\n<p>\u5bf9\u4e8e\u8fdb\u7a0b\u548c\u7ebf\u7a0b\u5927\u5bb6\u6709\u4e0d\u4e86\u89e3\u7684&#xff0c;\u53ef\u4ee5\u770b\u6211\u524d\u9762\u535a\u5ba2&#xff1a;[C&#043;&#043;\/Linux] Linux\u7ebf\u7a0b\u8be6\u89e3-CSDN\u535a\u5ba2<\/p>\n<\/p>\n<h4 id=\"2.2.4%E5%85%B6%E4%BB%96%E5%B9%B6%E5%8F%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%A8%A1%E5%9E%8B\">2.2.4\u5176\u4ed6\u5e76\u53d1\u670d\u52a1\u5668\u6a21\u578b<\/h4>\n<li>\n<p>\u4e8b\u4ef6\u9a71\u52a8\u670d\u52a1\u5668&#xff08;Event-Driven Server&#xff09;&#xff1a;\u00a0\u4e8b\u4ef6\u9a71\u52a8\u670d\u52a1\u5668\u4f7f\u7528\u975e\u963b\u585eIO\u548c\u4e8b\u4ef6\u5faa\u73af\u6765\u5904\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u8fde\u63a5\u3002\u670d\u52a1\u5668\u6ce8\u518c\u611f\u5174\u8da3\u7684\u4e8b\u4ef6&#xff08;\u5982\u53ef\u8bfb\u3001\u53ef\u5199\u4e8b\u4ef6&#xff09;&#xff0c;\u7136\u540e\u5728\u4e00\u4e2a\u5faa\u73af\u4e2d\u7b49\u5f85\u8fd9\u4e9b\u4e8b\u4ef6\u7684\u53d1\u751f\u3002\u5f53\u4e8b\u4ef6\u53d1\u751f\u65f6&#xff0c;\u670d\u52a1\u5668\u5904\u7406\u76f8\u5e94\u7684\u4e8b\u4ef6\u3002\u8fd9\u79cd\u6a21\u578b\u53ef\u4ee5\u975e\u5e38\u9ad8\u6548\u5730\u5904\u7406\u5927\u91cf\u8fde\u63a5\u3002<\/p>\n<\/li>\n<li>\n<p>\u5f02\u6b65IO\u670d\u52a1\u5668&#xff08;Asynchronous I\/O Server&#xff09;&#xff1a;\u00a0\u5f02\u6b65IO\u670d\u52a1\u5668\u4f7f\u7528\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7684\u5f02\u6b65IO\u63a5\u53e3\u6765\u5904\u7406\u8bf7\u6c42\u3002\u670d\u52a1\u5668\u53d1\u8d77IO\u64cd\u4f5c&#xff0c;\u7136\u540e\u7ee7\u7eed\u5904\u7406\u5176\u4ed6\u4efb\u52a1\u3002\u5f53IO\u64cd\u4f5c\u5b8c\u6210\u65f6&#xff0c;\u64cd\u4f5c\u7cfb\u7edf\u901a\u77e5\u670d\u52a1\u5668\u3002\u8fd9\u79cd\u6a21\u578b\u53ef\u4ee5\u5145\u5206\u5229\u7528CPU\u8d44\u6e90&#xff0c;\u56e0\u4e3a\u5b83\u4e0d\u9700\u8981\u4e3a\u6bcf\u4e2a\u8bf7\u6c42\u90fd\u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\u6216\u8fdb\u7a0b\u3002<\/p>\n<\/li>\n<h2 id=\"%E4%BA%8C.%E4%BD%BF%E7%94%A8%E4%BA%92%E6%96%A5%E9%94%81%E5%AE%9E%E7%8E%B0%E5%8D%95%E7%BA%BF%E7%A8%8B%E5%A4%84%E7%90%86%E5%8D%95%E4%B8%AA%E5%AE%A2%E6%88%B7\">\u4e8c.\u4f7f\u7528\u4e92\u65a5\u9501\u5b9e\u73b0\u5355\u7ebf\u7a0b\u5904\u7406\u5355\u4e2a\u5ba2\u6237<\/h2>\n<p>\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528\u4e92\u65a5\u9501\u6765\u5bf9\u6bcf\u4e2a\u8fdb\u884c\u4e0a\u9501&#xff0c;\u5b9e\u73b0\u5355\u5ba2\u6237\u5355\u8fdb\u7a0b\u5904\u7406&#xff0c;<\/p>\n<h3 id=\"2.1%20%E5%85%B7%E4%BD%93%E6%AD%A5%E9%AA%A4\">2.1 \u5177\u4f53\u6b65\u9aa4<\/h3>\n<li>\n<p>\u521d\u59cb\u5316\u4e92\u65a5\u9501&#xff1a;\u5728\u670d\u52a1\u5668\u542f\u52a8\u65f6&#xff0c;\u521d\u59cb\u5316\u4e00\u4e2a\u4e92\u65a5\u9501\u3002<\/p>\n<\/li>\n<li>\n<p>\u63a5\u53d7\u8fde\u63a5&#xff1a;\u670d\u52a1\u5668\u7684\u4e3b\u7ebf\u7a0b\u5faa\u73af\u63a5\u53d7\u5ba2\u6237\u7aef\u8fde\u63a5\u3002<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efa\u670d\u52a1\u7ebf\u7a0b&#xff1a;\u6bcf\u5f53\u63a5\u53d7\u4e00\u4e2a\u65b0\u8fde\u63a5\u65f6&#xff0c;\u670d\u52a1\u5668\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u670d\u52a1\u7ebf\u7a0b\u6765\u5904\u7406\u8be5\u8fde\u63a5\u3002<\/p>\n<\/li>\n<li>\n<p>\u52a0\u9501\u5904\u7406&#xff1a;\u5728\u6bcf\u4e2a\u670d\u52a1\u7ebf\u7a0b\u4e2d&#xff0c;\u5f53\u5f00\u59cb\u5904\u7406\u5ba2\u6237\u8bf7\u6c42\u4e4b\u524d&#xff0c;\u9996\u5148\u5c1d\u8bd5\u83b7\u53d6\u4e92\u65a5\u9501\u3002\u5982\u679c\u4e92\u65a5\u9501\u5df2\u88ab\u5176\u4ed6\u7ebf\u7a0b\u6301\u6709&#xff0c;\u7ebf\u7a0b\u5c06\u963b\u585e\u76f4\u5230\u4e92\u65a5\u9501\u88ab\u91ca\u653e\u3002<\/p>\n<\/li>\n<li>\n<p>\u5904\u7406\u8bf7\u6c42&#xff1a;\u7ebf\u7a0b\u83b7\u53d6\u4e92\u65a5\u9501\u540e&#xff0c;\u5f00\u59cb\u5904\u7406\u5ba2\u6237\u8bf7\u6c42\u3002<\/p>\n<\/li>\n<li>\n<p>\u91ca\u653e\u9501&#xff1a;\u5904\u7406\u5b8c\u8bf7\u6c42\u540e&#xff0c;\u7ebf\u7a0b\u91ca\u653e\u4e92\u65a5\u9501&#xff0c;\u4ee5\u4fbf\u5176\u4ed6\u7ebf\u7a0b\u53ef\u4ee5\u83b7\u53d6\u8be5\u9501\u5e76\u5904\u7406\u4e0b\u4e00\u4e2a\u8bf7\u6c42\u3002<\/p>\n<\/li>\n<li>\n<p>\u7ebf\u7a0b\u9000\u51fa&#xff1a;\u5904\u7406\u5b8c\u6210\u540e&#xff0c;\u7ebf\u7a0b\u9000\u51fa\u6216\u8fd4\u56de\u5230\u6c60\u4e2d\u7b49\u5f85\u4e0b\u4e00\u4e2a\u8bf7\u6c42<\/p>\n<\/li>\n<h3 id=\"2.2%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%BB%A3%E7%A0%81%E6%A8%A1%E6%9D%BF\">2.2\u670d\u52a1\u5668\u4ee3\u7801\u6a21\u677f<\/h3>\n<p>#include &lt;pthread.h&gt;<\/p>\n<p>pthread_mutex_t lock &#061; PTHREAD_MUTEX_INITIALIZER;<\/p>\n<p>void *handle_client(void *client_socket) {<br \/>\n    int socket &#061; *(int *)client_socket;<\/p>\n<p>    \/\/ \u52a0\u9501<br \/>\n    pthread_mutex_lock(&amp;lock);<\/p>\n<p>    \/\/ \u5904\u7406\u5ba2\u6237\u8bf7\u6c42<br \/>\n    \/\/ &#8230;<\/p>\n<p>    \/\/ \u91ca\u653e\u9501<br \/>\n    pthread_mutex_unlock(&amp;lock);<\/p>\n<p>    \/\/ \u5173\u95ed\u5ba2\u6237\u7aef\u5957\u63a5\u5b57<br \/>\n    close(socket);<br \/>\n    return NULL;<br \/>\n}<\/p>\n<p>int main() {<br \/>\n    \/\/ \u521b\u5efa\u76d1\u542c\u5957\u63a5\u5b57<br \/>\n    \/\/ &#8230;<\/p>\n<p>    while (1) {<br \/>\n        int client_socket &#061; accept(listen_socket, NULL, NULL);<\/p>\n<p>        \/\/ \u521b\u5efa\u7ebf\u7a0b\u6765\u5904\u7406\u5ba2\u6237\u7aef<br \/>\n        pthread_t thread;<br \/>\n        pthread_create(&amp;thread, NULL, handle_client, &amp;client_socket);<br \/>\n        pthread_detach(thread); \/\/ \u4f7f\u7ebf\u7a0b\u72ec\u7acb\u8fd0\u884c<br \/>\n    }<\/p>\n<p>    \/\/ \u5173\u95ed\u76d1\u542c\u5957\u63a5\u5b57<br \/>\n    \/\/ &#8230;<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<h2 id=\"%E4%B8%89.%E6%BA%90%E7%A0%81%E5%89%96%E6%9E%90\">\u4e09.\u6e90\u7801\u5256\u6790<\/h2>\n<p>#include&lt;t_stdio.h&gt;<br \/>\n#include&lt;t_file.h&gt;<br \/>\n#include&lt;stdlib.h&gt;<br \/>\n#include &lt;sys\/types.h&gt;<br \/>\n#include &lt;sys\/socket.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;arpa\/inet.h&gt;<br \/>\n#include&lt;unistd.h&gt;<br \/>\n#include&lt;time.h&gt;<br \/>\n#include&lt;pthread.h&gt;<br \/>\n#include &lt;string.h&gt;<\/p>\n<p>#define bufferlen 1024 \/\/\u53d1\u9001\/\u63a5\u6536\u6570\u636e\u7f13\u51b2\u533a\u5927\u5c0f<br \/>\n#define server_port 8888 \/\/\u7aef\u53e3<br \/>\n#define backlog 5 \/\/\u76d1\u542c\u961f\u5217<br \/>\n#define max_pthread 3 \/\/\u6700\u5927\u7ebf\u7a0b\u6570<\/p>\n<p>\/\/\u7ebf\u7a0b\u5904\u7406\u4e1a\u52a1\u51fd\u6570<br \/>\npthread_mutex_t ALOCK &#061; PTHREAD_MUTEX_INITIALIZER ;\/\/\u521b\u5efa\u4e92\u65a5\u91cf<\/p>\n<p>static void * handle_request(void * argv){<br \/>\n    int s_s &#061; *((int *) argv);<br \/>\n    int s_c;<br \/>\n    struct sockaddr_in from ;<br \/>\n    socklen_t len &#061; sizeof(from);<br \/>\n    for(;;){<br \/>\n        time_t now;<br \/>\n        char buf [bufferlen];<br \/>\n        int n&#061;0;<\/p>\n<p>        pthread_mutex_lock(&amp;ALOCK); \/\/\u8fdb\u5165\u4e92\u65a5\u533a<br \/>\n        s_c &#061; accept(s_s , (struct sockaddr *)&amp;from , &amp;len);\/\/\u63a5\u6536\u8bf7\u6c42<br \/>\n        pthread_mutex_unlock(&amp;ALOCK); \/\/\u79bb\u5f00\u4e92\u65a5\u533a<br \/>\n        memset(buf , 0 ,bufferlen);<br \/>\n        n &#061; recv(s_c , buf , bufferlen , 0);\/\/\u63a5\u6536\u6570\u636e<\/p>\n<p>        if(n &gt; 0 &amp;&amp; !strncmp(buf , &#034;TIME&#034; , 4))\/\/\u5224\u65ad\u662f\u5426\u4e3a\u5408\u6cd5\u63a5\u6536\u6570\u636e<br \/>\n        {<br \/>\n            memset(buf ,0 ,bufferlen);<br \/>\n            now &#061; time(NULL);<br \/>\n            sprintf(buf , &#034;%24s\\\\r\\\\n&#034;,ctime(&amp;now));\/\/\u65f6\u95f4\u5199\u5165buf<br \/>\n            send(s_c , buf , strlen(buf) , 0);\/\/\u53d1\u9001\u7ed9\u5ba2\u6237\u7aef<\/p>\n<p>        }<br \/>\n        close(s_c);<br \/>\n    }<br \/>\n    return ;<\/p>\n<p>}<\/p>\n<p>\/\/\u7ebf\u7a0b\u521b\u5efa\u51fd\u6570<br \/>\nstatic void handle_connect(int s){<br \/>\n    int s_s &#061;s;<br \/>\n    pthread_t thread_do[max_pthread];\/\/\u521b\u5efa\u7ebf\u7a0b\u6570\u7ec4<br \/>\n    int i&#061;0;<br \/>\n    \/\/\u521b\u5efa\u7ebf\u7a0b&#xff0c;\u6bcf\u4e00\u6b21\u521b\u5efa\u8c03\u7528\u7ebf\u7a0b\u5904\u7406\u51fd\u6570<br \/>\n    for(i &#061; 0; i&lt;max_pthread;i&#043;&#043;){<br \/>\n        pthread_create(&amp;thread_do[i] , NULL, handle_request , (void *)&amp;s_s);<br \/>\n    }<br \/>\n    \/\/\u7b49\u5f85\u7ebf\u7a0b\u7ed3\u675f<br \/>\n    for(i &#061; 0; i&lt;max_pthread;i&#043;&#043;){<br \/>\n        pthread_join(thread_do[i] , NULL);<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p>int main(int argc ,char * argvp[]){<br \/>\n    int s_s;<br \/>\n    struct sockaddr_in local ;\/\/\u672c\u5730\u5730\u5740<br \/>\n    s_s &#061; socket(AF_INET , SOCK_STREAM , 0);<br \/>\n    memset(&amp;local , 0 , sizeof(local));<br \/>\n    local.sin_family &#061; AF_INET;<br \/>\n    local.sin_addr.s_addr &#061; htonl(INADDR_ANY);<br \/>\n    local.sin_port &#061; htons(server_port);<\/p>\n<p>    bind(s_s , (struct sockaddr *)&amp;local ,sizeof(local));\/\/\u8fde\u63a5\u672c\u5730\u5730\u5740<br \/>\n    listen(s_s , backlog);\/\/\u521b\u5efa\u76d1\u542c\u961f\u5217<br \/>\n    handle_connect(s_s);<br \/>\n    close(s_s);<\/p>\n<p>    return 0;<br \/>\n} <\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u7f51\u7edc\u670d\u52a1\u5668\u793a\u4f8b&#xff0c;\u5b83\u4f7f\u7528\u4e86 POSIX \u7ebf\u7a0b&#xff08;pthread&#xff09;\u6765\u5904\u7406\u5ba2\u6237\u7aef\u8bf7\u6c42\u3002\u4e0b\u9762\u6211\u5c06\u9010\u884c\u89e3\u91ca\u4ee3\u7801\u7684\u529f\u80fd&#xff1a;<\/p>\n<p>#include &lt;t_stdio.h&gt;<br \/>\n#include &lt;t_file.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;sys\/types.h&gt;<br \/>\n#include &lt;sys\/socket.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;arpa\/inet.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include &lt;time.h&gt;<br \/>\n#include &lt;pthread.h&gt;<br \/>\n#include &lt;string.h&gt;<\/p>\n<p>\u8fd9\u91cc\u5305\u542b\u4e86\u5fc5\u8981\u7684\u5934\u6587\u4ef6&#xff0c;\u5305\u62ec\u6807\u51c6\u8f93\u5165\u8f93\u51fa\u3001\u6587\u4ef6\u64cd\u4f5c\u3001\u7f51\u7edc\u7f16\u7a0b\u3001\u5b57\u7b26\u4e32\u64cd\u4f5c\u3001IP\u5730\u5740\u8f6c\u6362\u3001\u975e\u963b\u585eI\/O\u7b49\u3002<\/p>\n<p>#define bufferlen 1024 \/\/\u53d1\u9001\/\u63a5\u6536\u6570\u636e\u7f13\u51b2\u533a\u5927\u5c0f<br \/>\n#define server_port 8888 \/\/\u7aef\u53e3<br \/>\n#define backlog 5 \/\/\u76d1\u542c\u961f\u5217<br \/>\n#define max_pthread 3 \/\/\u6700\u5927\u7ebf\u7a0b\u6570<\/p>\n<p>\u5b9a\u4e49\u4e86\u4e00\u4e9b\u5b8f&#xff0c;\u7528\u4e8e\u8bbe\u7f6e\u7f13\u51b2\u533a\u5927\u5c0f\u3001\u670d\u52a1\u5668\u7aef\u53e3\u3001\u76d1\u542c\u961f\u5217\u5927\u5c0f\u548c\u6700\u5927\u7ebf\u7a0b\u6570\u3002<\/p>\n<p>\/\/\u7ebf\u7a0b\u5904\u7406\u4e1a\u52a1\u51fd\u6570<br \/>\npthread_mutex_t ALOCK &#061; PTHREAD_MUTEX_INITIALIZER ;\/\/\u521b\u5efa\u4e92\u65a5\u91cf<\/p>\n<p>\u5b9a\u4e49\u4e86\u4e00\u4e2a\u4e92\u65a5\u91cf\u00a0ALOCK&#xff0c;\u7528\u4e8e\u7ebf\u7a0b\u95f4\u7684\u540c\u6b65\u3002<\/p>\n<p>static void * handle_request(void * argv){<br \/>\n    int s_s &#061; *((int *) argv);<br \/>\n    int s_c;<br \/>\n    struct sockaddr_in from ;<br \/>\n    socklen_t len &#061; sizeof(from);<br \/>\n    for(;;){<br \/>\n        time_t now;<br \/>\n        char buf [bufferlen];<br \/>\n        int n&#061;0;<\/p>\n<p>        pthread_mutex_lock(&amp;ALOCK); \/\/\u8fdb\u5165\u4e92\u65a5\u533a<br \/>\n        s_c &#061; accept(s_s , (struct sockaddr *)&amp;from , &amp;len);\/\/\u63a5\u6536\u8bf7\u6c42<br \/>\n        pthread_mutex_unlock(&amp;ALOCK); \/\/\u79bb\u5f00\u4e92\u65a5\u533a<br \/>\n        memset(buf , 0 ,bufferlen);<br \/>\n        n &#061; recv(s_c , buf , bufferlen , 0);\/\/\u63a5\u6536\u6570\u636e<\/p>\n<p>        if(n &gt; 0 &amp;&amp; !strncmp(buf , &#034;TIME&#034; , 4))\/\/\u5224\u65ad\u662f\u5426\u4e3a\u5408\u6cd5\u63a5\u6536\u6570\u636e<br \/>\n        {<br \/>\n            memset(buf ,0 ,bufferlen);<br \/>\n            now &#061; time(NULL);<br \/>\n            sprintf(buf , &#034;%24s\\\\r\\\\n&#034;,ctime(&amp;now));\/\/\u65f6\u95f4\u5199\u5165buf<br \/>\n            send(s_c , buf , strlen(buf) , 0);\/\/\u53d1\u9001\u7ed9\u5ba2\u6237\u7aef<\/p>\n<p>        }<br \/>\n        close(s_c);<br \/>\n    }<br \/>\n    return ;<br \/>\n}<\/p>\n<p>handle_request\u00a0\u51fd\u6570\u662f\u7ebf\u7a0b\u5904\u7406\u4e1a\u52a1\u7684\u6838\u5fc3\u3002\u5b83\u63a5\u53d7\u4e00\u4e2a\u6574\u6570\u53c2\u6570\u00a0s_s&#xff0c;\u8fd9\u662f\u670d\u52a1\u5668\u5957\u63a5\u5b57\u3002\u51fd\u6570\u8fdb\u5165\u4e00\u4e2a\u65e0\u9650\u5faa\u73af&#xff0c;\u63a5\u6536\u5ba2\u6237\u7aef\u7684\u8fde\u63a5&#xff08;accept\u00a0\u8c03\u7528&#xff09;&#xff0c;\u63a5\u6536\u6570\u636e&#xff08;recv\u00a0\u8c03\u7528&#xff09;&#xff0c;\u5904\u7406\u6570\u636e&#xff08;\u5982\u679c\u6570\u636e\u662f\u4ee5 \u201cTIME\u201d \u5f00\u5934\u7684&#xff0c;\u5219\u8fd4\u56de\u5f53\u524d\u65f6\u95f4&#xff09;&#xff0c;\u7136\u540e\u5173\u95ed\u5ba2\u6237\u7aef\u5957\u63a5\u5b57\u3002<\/p>\n<\/p>\n<p>\u00a0\u00a0\u597d\u5566&#xff01;\u5230\u8fd9\u91cc\u8fd9\u7bc7\u6587\u7ae0\u5c31\u7ed3\u675f\u5566&#xff0c;\u5173\u4e8e\u5b9e\u4f8b\u4ee3\u7801\u4e2d\u6211\u5199\u4e86\u5f88\u591a\u6ce8\u91ca&#xff0c;\u5982\u679c\u5927\u5bb6\u8fd8\u6709\u4e0d\u61c2\u5f97&#xff0c;\u53ef\u4ee5\u8bc4\u8bba\u533a\u6216\u8005\u79c1\u4fe1\u6211\u90fd\u53ef\u4ee5\u54e6<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"28\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418100715-68022453b17ec.png\" width=\"28\" \/>&#xff01;&#xff01; \u611f\u8c22\u5927\u5bb6\u7684\u9605\u8bfb&#xff0c;\u6211\u8fd8\u4f1a\u6301\u7eed\u521b\u9020\u7f51\u7edc\u7f16\u7a0b\u76f8\u5173\u5185\u5bb9\u7684&#xff0c;\u8bb0\u5f97\u70b9\u70b9\u5c0f\u7231\u5fc3\u548c\u5173\u6ce8\u54df&#xff01;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"48\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418100715-68022453b7b5a.jpg\" width=\"50\" \/>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb4.5k\u6b21\uff0c\u70b9\u8d5e85\u6b21\uff0c\u6536\u85cf89\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u5728\u7f51\u7edc\u7f16\u7a0b\u4e2d\u6784\u5efa\u9ad8\u6027\u80fd\u5e76\u53d1\u670d\u52a1\u5668\u7684\u65b9\u6cd5\uff0c\u5305\u62ec\u666e\u901a\u5faa\u73af\u670d\u52a1\u5668\u3001\u591a\u8fdb\u7a0b\u548c\u591a\u7ebf\u7a0b\u5e76\u53d1\u6a21\u578b\uff0c\u4ee5\u53ca\u4f7f\u7528\u4e92\u65a5\u9501\u5b9e\u73b0\u5355\u7ebf\u7a0b\u5904\u7406\u5355\u4e2a\u5ba2\u6237\u3002\u4f5c\u8005\u63d0\u4f9b\u4e86\u6e90\u7801\u5256\u6790\u548cUML\u56fe\u793a\u4f8b\uff0c\u5e2e\u52a9\u8bfb\u8005\u7406\u89e3\u5e76\u53d1\u670d\u52a1\u5668\u7684\u5de5\u4f5c\u539f\u7406\u548c\u5b9e\u73b0\u7b56\u7565\u3002<\/p>\n","protected":false},"author":2,"featured_media":10588,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,58,464,193,43,78,44],"topic":[],"class_list":{"0":"post-10597","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","6":"hentry","7":"category-server","8":"tag-c","9":"tag-linux","11":"tag-udp","12":"tag-43","13":"tag-78","14":"tag-44"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010\u7f51\u7edc\u7f16\u7a0b\u3011\u9ad8\u6027\u80fd\u5e76\u53d1\u670d\u52a1\u5668\u6e90\u7801\u5256\u6790 - \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\/10597.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010\u7f51\u7edc\u7f16\u7a0b\u3011\u9ad8\u6027\u80fd\u5e76\u53d1\u670d\u52a1\u5668\u6e90\u7801\u5256\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb4.5k\u6b21\uff0c\u70b9\u8d5e85\u6b21\uff0c\u6536\u85cf89\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u5728\u7f51\u7edc\u7f16\u7a0b\u4e2d\u6784\u5efa\u9ad8\u6027\u80fd\u5e76\u53d1\u670d\u52a1\u5668\u7684\u65b9\u6cd5\uff0c\u5305\u62ec\u666e\u901a\u5faa\u73af\u670d\u52a1\u5668\u3001\u591a\u8fdb\u7a0b\u548c\u591a\u7ebf\u7a0b\u5e76\u53d1\u6a21\u578b\uff0c\u4ee5\u53ca\u4f7f\u7528\u4e92\u65a5\u9501\u5b9e\u73b0\u5355\u7ebf\u7a0b\u5904\u7406\u5355\u4e2a\u5ba2\u6237\u3002\u4f5c\u8005\u63d0\u4f9b\u4e86\u6e90\u7801\u5256\u6790\u548cUML\u56fe\u793a\u4f8b\uff0c\u5e2e\u52a9\u8bfb\u8005\u7406\u89e3\u5e76\u53d1\u670d\u52a1\u5668\u7684\u5de5\u4f5c\u539f\u7406\u548c\u5b9e\u73b0\u7b56\u7565\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/10597.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-18T10:07:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418100714-68022452cd1c8.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=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/10597.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/10597.html\",\"name\":\"\u3010\u7f51\u7edc\u7f16\u7a0b\u3011\u9ad8\u6027\u80fd\u5e76\u53d1\u670d\u52a1\u5668\u6e90\u7801\u5256\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T10:07:16+00:00\",\"dateModified\":\"2025-04-18T10:07:16+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/10597.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/10597.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/10597.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010\u7f51\u7edc\u7f16\u7a0b\u3011\u9ad8\u6027\u80fd\u5e76\u53d1\u670d\u52a1\u5668\u6e90\u7801\u5256\u6790\"}]},{\"@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":"\u3010\u7f51\u7edc\u7f16\u7a0b\u3011\u9ad8\u6027\u80fd\u5e76\u53d1\u670d\u52a1\u5668\u6e90\u7801\u5256\u6790 - \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\/10597.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010\u7f51\u7edc\u7f16\u7a0b\u3011\u9ad8\u6027\u80fd\u5e76\u53d1\u670d\u52a1\u5668\u6e90\u7801\u5256\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb4.5k\u6b21\uff0c\u70b9\u8d5e85\u6b21\uff0c\u6536\u85cf89\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u5728\u7f51\u7edc\u7f16\u7a0b\u4e2d\u6784\u5efa\u9ad8\u6027\u80fd\u5e76\u53d1\u670d\u52a1\u5668\u7684\u65b9\u6cd5\uff0c\u5305\u62ec\u666e\u901a\u5faa\u73af\u670d\u52a1\u5668\u3001\u591a\u8fdb\u7a0b\u548c\u591a\u7ebf\u7a0b\u5e76\u53d1\u6a21\u578b\uff0c\u4ee5\u53ca\u4f7f\u7528\u4e92\u65a5\u9501\u5b9e\u73b0\u5355\u7ebf\u7a0b\u5904\u7406\u5355\u4e2a\u5ba2\u6237\u3002\u4f5c\u8005\u63d0\u4f9b\u4e86\u6e90\u7801\u5256\u6790\u548cUML\u56fe\u793a\u4f8b\uff0c\u5e2e\u52a9\u8bfb\u8005\u7406\u89e3\u5e76\u53d1\u670d\u52a1\u5668\u7684\u5de5\u4f5c\u539f\u7406\u548c\u5b9e\u73b0\u7b56\u7565\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/10597.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T10:07:16+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418100714-68022452cd1c8.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/10597.html","url":"https:\/\/www.wsisp.com\/helps\/10597.html","name":"\u3010\u7f51\u7edc\u7f16\u7a0b\u3011\u9ad8\u6027\u80fd\u5e76\u53d1\u670d\u52a1\u5668\u6e90\u7801\u5256\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T10:07:16+00:00","dateModified":"2025-04-18T10:07:16+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/10597.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/10597.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/10597.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010\u7f51\u7edc\u7f16\u7a0b\u3011\u9ad8\u6027\u80fd\u5e76\u53d1\u670d\u52a1\u5668\u6e90\u7801\u5256\u6790"}]},{"@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\/10597","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=10597"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/10597\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/10588"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=10597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=10597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=10597"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=10597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}