{"id":9725,"date":"2025-04-18T17:37:04","date_gmt":"2025-04-18T09:37:04","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/9725.html"},"modified":"2025-04-18T17:37:04","modified_gmt":"2025-04-18T09:37:04","slug":"%e3%80%90javaee%e5%88%9d%e9%98%b6%e3%80%91%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8btcp%e5%8d%8f%e8%ae%ae%e5%ae%9e%e7%8e%b0%e5%9b%9e%e6%98%be%e6%9c%8d%e5%8a%a1%e5%99%a8%e4%bb%a5%e5%8f%8a%e5%a6%82%e4%bd%95","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/9725.html","title":{"rendered":"\u3010JavaEE\u521d\u9636\u3011\u7f51\u7edc\u7f16\u7a0bTCP\u534f\u8bae\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668\u4ee5\u53ca\u5982\u4f55\u5904\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u7684\u54cd\u5e94"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"552\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418093702-68021d3e20339.png\" width=\"1200\" \/><\/p>\n<p><span style=\"color:#956fe7\">\u524d\u8a00<\/span><\/p>\n<p><span style=\"color:#38d8f0\">&#x1f31f;&#x1f31f;\u672c\u671f\u8bb2\u89e3\u5173\u4e8eTCP\/UDP\u534f\u8bae\u7684\u539f\u7406\u7406\u89e3~~~<\/span><\/p>\n<p><span style=\"color:#38d8f0\">&#x1f308;\u611f\u5174\u8da3\u7684\u5c0f\u4f19\u4f34\u770b\u4e00\u770b\u5c0f\u7f16\u4e3b\u9875&#xff1a;<\/span>GGBondlctrl-CSDN\u535a\u5ba2<\/p>\n<p><span style=\"color:#38d8f0\">&#x1f525; \u4f60\u7684\u70b9\u8d5e\u5c31\u662f\u5c0f\u7f16\u4e0d\u65ad\u66f4\u65b0\u7684\u6700\u5927\u52a8\u529b \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<\/span><\/p>\n<p><span style=\"color:#38d8f0\">&#x1f386;\u90a3\u4e48\u5e9f\u8bdd\u4e0d\u591a\u8bf4\u76f4\u63a5\u5f00\u6574\u5427~~<\/span><\/p>\n<p style=\"text-align:center\">\u00a0<img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418093702-68021d3e89aeb.gif\" \/><\/p>\n<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%F0%9F%93%9A%EF%B8%8F1.TCP%E7%9B%B8%E5%85%B3API-toc\" style=\"margin-left:40px\">&#x1f4da;\ufe0f1.TCP\u76f8\u5173API<\/p>\n<p id=\"%F0%9F%93%9A%EF%B8%8F2.%E5%9B%9E%E6%98%BE%E6%9C%8D%E5%8A%A1%E5%99%A8-toc\" style=\"margin-left:40px\">&#x1f4da;\ufe0f2.\u56de\u663e\u670d\u52a1\u5668<\/p>\n<p id=\"2.1%E6%A6%82%E5%BF%B5-toc\" style=\"margin-left:80px\">2.1\u6982\u5ff5<\/p>\n<p id=\"2.2%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%9A%84%E5%AE%9E%E7%8E%B0-toc\" style=\"margin-left:80px\">2.2\u670d\u52a1\u5668\u7684\u5b9e\u73b0<\/p>\n<p id=\"1.%E5%88%9D%E5%A7%8B%E5%8C%96Socket%E7%B1%BB%E5%AF%B9%E8%B1%A1-toc\" style=\"margin-left:120px\">1.\u521d\u59cb\u5316Socket\u7c7b\u5bf9\u8c61<\/p>\n<p id=\"2.%E5%90%AF%E5%8A%A8%E8%BF%9E%E6%8E%A5%E6%9C%8D%E5%8A%A1%E5%99%A8-toc\" style=\"margin-left:120px\">2.\u542f\u52a8\u8fde\u63a5\u670d\u52a1\u5668<\/p>\n<p id=\"%C2%A03.%E8%AF%BB%E5%8F%96%E8%BF%9E%E6%8E%A5%E7%9A%84%E9%98%BB%E5%A1%9E-toc\" style=\"margin-left:120px\">\u00a03.\u8bfb\u53d6\u8fde\u63a5\u7684\u963b\u585e<\/p>\n<p id=\"4.%E6%95%B0%E6%8D%AE%E7%9A%84%E5%93%8D%E5%BA%94%E7%9A%84%E8%BF%94%E5%9B%9E-toc\" style=\"margin-left:120px\">4.\u6570\u636e\u7684\u54cd\u5e94\u7684\u8fd4\u56de<\/p>\n<p id=\"5.%E7%BC%93%E5%86%B2%E5%8C%BA%E7%9A%84%E5%88%B7%E6%96%B0-toc\" style=\"margin-left:120px\">5.\u7f13\u51b2\u533a\u7684\u5237\u65b0<\/p>\n<p id=\"2.3%E5%AE%A2%E6%88%B7%E7%AB%AF%E7%9A%84%E5%AE%9E%E7%8E%B0-toc\" style=\"margin-left:80px\">2.3\u5ba2\u6237\u7aef\u7684\u5b9e\u73b0<\/p>\n<p id=\"1.%E5%88%9D%E5%A7%8B%E5%8C%96Socket%E7%B1%BB%E5%AF%B9%E8%B1%A1-toc\" style=\"margin-left:120px\">1.\u521d\u59cb\u5316Socket\u7c7b\u5bf9\u8c61<\/p>\n<p id=\"2.%E5%90%AF%E5%8A%A8%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%B9%B6%E9%98%BB%E5%A1%9E-toc\" style=\"margin-left:120px\">2.\u542f\u52a8\u5ba2\u6237\u7aef\u5e76\u963b\u585e<\/p>\n<p id=\"3.%E5%8F%91%E9%80%81%E8%AF%B7%E6%B1%82%E5%92%8C%E6%8E%A5%E6%94%B6%E5%93%8D%E5%BA%94-toc\" style=\"margin-left:120px\">3.\u53d1\u9001\u8bf7\u6c42\u548c\u63a5\u6536\u54cd\u5e94<\/p>\n<p id=\"4.%E6%96%87%E4%BB%B6%E6%B5%81close%E7%9A%84%E6%93%8D%E4%BD%9C-toc\" style=\"margin-left:120px\">4.\u6587\u4ef6\u6d41close\u7684\u64cd\u4f5c<\/p>\n<p id=\"%F0%9F%93%9A%EF%B8%8F3.%E5%A4%84%E7%90%86%E5%A4%9A%E4%B8%AA%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%90%8C%E6%97%B6%E5%93%8D%E5%BA%94-toc\" style=\"margin-left:40px\">&#x1f4da;\ufe0f3.\u5904\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u540c\u65f6\u54cd\u5e94<\/p>\n<p id=\"3.1%E5%90%AF%E5%8A%A8%E5%A4%9A%E4%B8%AA%E6%9C%8D%E5%8A%A1%E5%99%A8-toc\" style=\"margin-left:80px\">3.1\u542f\u52a8\u591a\u4e2a\u670d\u52a1\u5668<\/p>\n<p id=\"3.2%E5%A4%84%E7%90%86%E5%A4%9A%E5%AE%A2%E6%88%B7%E7%AB%AF%E8%AF%B7%E6%B1%82-toc\" style=\"margin-left:80px\">3.2\u5904\u7406\u591a\u5ba2\u6237\u7aef\u8bf7\u6c42<\/p>\n<p id=\"1.%E9%97%AE%E9%A2%98%E7%8E%B0%E8%B1%A1-toc\" style=\"margin-left:120px\">1.\u95ee\u9898\u73b0\u8c61<\/p>\n<p id=\"2.%E9%97%AE%E9%A2%98%E5%88%86%E6%9E%90-toc\" style=\"margin-left:120px\">2.\u95ee\u9898\u5206\u6790<\/p>\n<p id=\"3.%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3-toc\" style=\"margin-left:120px\">3.\u95ee\u9898\u89e3\u51b3<\/p>\n<p id=\"4.%E6%96%B9%E6%B3%95%E6%89%A9%E5%B1%95-toc\" style=\"margin-left:120px\">4.\u65b9\u6cd5\u6269\u5c55<\/p>\n<p id=\"%F0%9F%93%9A%EF%B8%8F4.%E6%80%BB%E7%BB%93-toc\" style=\"margin-left:40px\">&#x1f4da;\ufe0f4.\u603b\u7ed3<\/p>\n<\/p>\n<p style=\"text-align:center\">\u00a0<img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418093702-68021d3e9355c.gif\" \/><\/p>\n<h3 id=\"%F0%9F%93%9A%EF%B8%8F1.TCP%E7%9B%B8%E5%85%B3API\">&#x1f4da;\ufe0f1.TCP\u76f8\u5173API<\/h3>\n<p>\u00a0\u548c\u524d\u4e00\u671f\u7684UDP\u57fa\u672c\u662f\u5927\u5dee\u4e0d\u5dee\u7684&#xff0c;\u4f46\u662f\u8fd9\u91cc\u63d0\u4f9b\u7684\u65b9\u6cd5\u6765\u6a21\u62df\u5bf9\u4e8e\u7f51\u5361\u7684\u64cd\u4f5c\u662f\u6709\u4e00\u5b9a\u7684\u533a\u522b\u7684&#xff0c;\u6240\u793aAPI\u5982\u4e0b&#xff1a;<\/p>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:500px\">\n<tbody>\n<tr>\n<td>ServerSocket<\/td>\n<td>\u662fSocket\u7c7b\u5bf9\u5e94\u5230\u7f51\u5361\u7ed9\u670d\u52a1\u5668\u4f7f\u7528\u7684\u7c7b<\/td>\n<\/tr>\n<tr>\n<td>Socket<\/td>\n<td>\u5bf9\u5e94\u5230\u7f51\u5361&#xff0c;\u662f\u7ed9\u670d\u52a1\u5668\u6216\u8005\u5ba2\u6237\u7aef\u6765\u8fdb\u884c\u4f7f\u7528\u7684<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u800c\u6211\u4eec\u77e5\u9053\u5728UDP\u7684\u4f7f\u7528\u4e2d\u6709DatagramPacket\u662f\u7528\u4e8e\u5728\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u7684\u6570\u636e\u4f20\u9001\u7684\u5355\u4f4d&#xff0c;\u5373\u201c\u9762\u5411\u6570\u636e\u5305\u201d&#xff0c;\u4f46\u662f\u8fd9\u91cc\u662f\u6ca1\u6709\u5177\u4f53\u7279\u6709\u7684\u6570\u636e\u4f20\u9001\u7684\u7c7b\u7684<\/p>\n<p>\u6ce8\u610f&#xff1a;\u7531\u4e8eTCP\u662f\u4e00\u4e2a\u9762\u5411\u5b57\u8282\u6d41\u7684\u534f\u8bae&#xff0c;\u6240\u4ee5\u4f7f\u7528\u7684\u4ecd\u7136\u662f\u6587\u4ef6IO\u90e8\u5206\u7684\u64cd\u4f5c\u5b57\u8282\u6d41&#xff1b;<\/p>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:500px\">\n<tbody>\n<tr>\n<td>inputstream<\/td>\n<td>\u8bfb\u6570\u636e&#xff08;\u5b57\u8282\u4e3a\u5355\u4f4d&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>outputstream<\/td>\n<td>\u5199\u6570\u636e&#xff08;\u5b57\u8282\u4e3a\u5355\u4f4d&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6240\u4ee5\u6709\u4e86\u8fd9\u4e9b\u94fa\u57ab\u6211\u4eec\u5c31\u53ef\u4ee5\u4f7f\u7528TCP\u6765\u5b9e\u73b0\u4e00\u4e2a\u56de\u663e\u670d\u52a1\u5668\u4e86&#xff1b;<\/p>\n<h3 id=\"%F0%9F%93%9A%EF%B8%8F2.%E5%9B%9E%E6%98%BE%E6%9C%8D%E5%8A%A1%E5%99%A8\">&#x1f4da;\ufe0f2.\u56de\u663e\u670d\u52a1\u5668<\/h3>\n<h4 id=\"2.1%E6%A6%82%E5%BF%B5\">2.1\u6982\u5ff5<\/h4>\n<p>\u56de\u663e\u670d\u52a1\u5668&#xff1a;\u6240\u8c13\u7684\u56de\u663e\u670d\u52a1\u5668\u5c31\u662f\u5f53\u5ba2\u6237\u7aef\u53d1\u9001\u4e00\u4e2a\u8bf7\u6c42\u4e4b\u540e&#xff0c;\u670d\u52a1\u5668\u5c31\u76f4\u63a5\u8fd4\u56de\u8fd9\u4e2a\u54cd\u5e94&#xff0c;\u5728\u5bf9\u4e8e\u8bf7\u6c42\u7684\u89e3\u6790\u548c\u64cd\u4f5c\u4e2d\u662f\u6ca1\u6709\u4efb\u4f55\u7684\u903b\u8f91\u7684&#xff1b;&#xff08;<span style=\"background-color:#ffd900\">\u603b\u4e4b\u5c31\u662f\u7528\u6237\u8f93\u5165\u4ec0\u4e48\u5c31\u5f97\u5230\u4ec0\u4e48~~<\/span>&#xff09;<\/p>\n<h4 id=\"2.2%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%9A%84%E5%AE%9E%E7%8E%B0\">2.2\u670d\u52a1\u5668\u7684\u5b9e\u73b0<\/h4>\n<h5 id=\"1.%E5%88%9D%E5%A7%8B%E5%8C%96Socket%E7%B1%BB%E5%AF%B9%E8%B1%A1\">1.\u521d\u59cb\u5316Socket\u7c7b\u5bf9\u8c61<\/h5>\n<p>\u8fd9\u91cc\u548cUDP\u7684\u521d\u59cb\u5316\u51e0\u4e4e\u662f\u4e00\u6837\u7684&#xff0c;\u5373\u5982\u4e0b\u4ee3\u7801\u6240\u793a&#xff1a;<\/p>\n<p>public class TcpEchoServer {<br \/>\n    private ServerSocket serverSocket &#061; null;<\/p>\n<p>    public TcpEchoServer(int port) throws IOException {<br \/>\n        serverSocket &#061; new ServerSocket(port);  \/\/\u64cd\u4f5c\u6a21\u62df\u7f51\u5361\u7684\u7aef\u53e3\u53f7<br \/>\n    } <\/p>\n<p>\u8fd9\u91cc\u5c31\u662f\u901a\u8fc7erverSocket\u7c7b\u6765\u5b9e\u73b0\u4e00\u4e2a\u5bf9\u8c61&#xff0c;\u8fbe\u5230\u6a21\u62df\u63a7\u5236\u7f51\u5361\u7684\u64cd\u4f5c&#xff0c;\u7528\u4e8e\u6570\u636e\u7684\u4f20\u8f93&#xff0c;\u5176\u4e2d\u8fd9\u91cc\u7684port\u5c31\u662f\u4e00\u4e2a\u670d\u52a1\u5668\u7684\u7aef\u53e3\u53f7&#xff1b;<\/p>\n<h5 id=\"2.%E5%90%AF%E5%8A%A8%E8%BF%9E%E6%8E%A5%E6%9C%8D%E5%8A%A1%E5%99%A8\">2.\u542f\u52a8\u8fde\u63a5\u670d\u52a1\u5668<\/h5>\n<p>\u5728\u4e0a\u8ff0\u7684\u521d\u59cb\u5316\u8fc7\u540e&#xff0c;\u6211\u4eec\u5c31\u53ef\u76f4\u63a5\u542f\u52a8\u670d\u52a1\u5668\u4e86&#xff0c;\u4ee3\u7801\u6240\u793a&#xff1a;<\/p>\n<p> public void start() throws IOException {<br \/>\n        System.out.println(&#034;\u670d\u52a1\u5668\u542f\u52a8\u4e86&#034;);<br \/>\n        \/\/\u8fdb\u5165\u5faa\u73af<br \/>\n        while (true) {<br \/>\n            \/\/\u5efa\u7acb\u8fde\u63a5<br \/>\n            Socket Clientsocket &#061; serverSocket.accept();<br \/>\n            processClient(Clientsocket);<br \/>\n        }<br \/>\n    } <\/p>\n<p>\u89e3\u91ca&#xff1a;\u5f53\u6211\u4eec\u542f\u52a8\u670d\u52a1\u5668\u4e4b\u540e&#xff0c;\u8fd9\u91cc\u5c31\u8981\u8fdb\u884c\u670d\u52a1\u5668\u4e0e\u5ba2\u6237\u7aef\u7684\u8fde\u63a5&#xff0c;\u4e3a\u5565\u8981\u8fdb\u884c\u8fde\u63a5\u5462&#xff0c;\u4e3b\u8981\u662f\u56e0\u4e3aTCP\u662f\u4e00\u4e2a\u6709\u8fde\u63a5\u7684\u534f\u8bae&#xff0c;\u8fd9\u5c31\u7c7b\u4f3c\u4e8e\u6253\u7535\u8bdd\u4e00\u6837&#xff0c;\u4e24\u8fb9\u8981\u63a5\u542c\u540e\u624d\u80fd\u591f\u8fdb\u884c\u901a\u4fe1&#xff0c;\u7136\u540e\u5c06\u6570\u636e\u4f20\u7ed9\u53e6\u4e00\u4e2a\u65b9\u6cd5\u64cd\u4f5c&#xff1b;<\/p>\n<p>\u5982\u4e0b\u56fe\u6240\u793a&#xff1a;<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418093702-68021d3e9eaaf.png\" \/><\/p>\n<p>\u6b64\u65f6\u5e94\u7528\u7a0b\u5e8f\u4e2d\u8c03\u7528\u5bf9\u5e94\u7684API\u6765\u5c1d\u8bd5\u548c\u670d\u52a1\u5668\u5efa\u7acb\u8fde\u63a5&#xff0c;\u7136\u540e\u5185\u6838\u6001\u5c31\u4f1a\u5c1d\u8bd5\u53d1\u8d77\u5efa\u7acb\u8fde\u63a5\u7684\u6d41\u7a0b&#xff0c;\u7136\u540e\u670d\u52a1\u5668\u8fd9\u8fb9\u7684\u5185\u6838\u6001\u5c31\u4f1a\u914d\u5408\u8fdb\u884c\u8fde\u63a5&#xff1b;<\/p>\n<p>\u6ce8\u610f&#xff1a;\u5185\u6838\u53d1\u8d77\u8fde\u63a5\u662f\u7528\u6237\u7a0b\u5e8f\u6765\u8fdb\u884c\u64cd\u4f5c\u7684&#xff0c;\u6240\u4ee5\u8fd9\u91cc\u5c31\u8981\u8c03\u7528accept\u6765\u8fdb\u884c\u8fde\u63a5&#xff1b;<\/p>\n<h5 id=\"%C2%A03.%E8%AF%BB%E5%8F%96%E8%BF%9E%E6%8E%A5%E7%9A%84%E9%98%BB%E5%A1%9E\">\u00a03.\u8bfb\u53d6\u8fde\u63a5\u7684\u963b\u585e<\/h5>\n<p>\u5f53\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u5efa\u7acb\u8fde\u63a5&#xff0c;\u4f20\u5165\u6570\u636e\u8fdb\u884c\u64cd\u4f5c\u65f6&#xff0c;\u6b64\u65f6\u670d\u52a1\u5668\u5c31\u4f1a\u8fdb\u5165\u963b\u585e\u72b6\u6001&#xff0c;\u90a3\u4e48\u5c31\u6709\u4e00\u4e0b\u4ee3\u7801\u6765\u8fdb\u884c\u5b9e\u73b0&#xff1a;<\/p>\n<p>private void processClient(Socket Clientsocket) { \/\/\u5904\u7406\u8fde\u63a5\u6765\u7684\u6570\u636e<br \/>\n        System.out.printf(&#034;[%s:%d] \u5ba2\u6237\u7aef\u4e0a\u7ebf!\\\\n&#034;, Clientsocket.getInetAddress(), Clientsocket.getPort());<\/p>\n<p>        try (InputStream inputStream &#061; Clientsocket.getInputStream();<br \/>\n             OutputStream OutputStream &#061; Clientsocket.getOutputStream()) {<br \/>\n            \/\/\u5faa\u73af\u8bfb\u53d6\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\u5e76\u4e14\u8fdb\u884c\u54cd\u5e94<br \/>\n            while (true) {<br \/>\n                Scanner scanner &#061; new Scanner(inputStream);<br \/>\n                if (!scanner.hasNext()) {<br \/>\n                    System.out.printf(&#034;[%s:%d] \u5ba2\u6237\u7aef\u4e0b\u7ebf!\\\\n&#034;, Clientsocket.getInetAddress(), Clientsocket.getPort());<br \/>\n                    break;<br \/>\n                } <\/p>\n<p>\u89e3\u91ca&#xff1a;<\/p>\n<p>\u7531\u4e8eTCP\u7684\u9762\u5411\u5b57\u8282\u6d41&#xff0c;\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7inputstream\u6765\u5b9e\u73b0\u8fd9\u91cc\u7684\u64cd\u4f5c&#xff0c;\u6b64\u65f6\u5c06\u8fd9\u91cc\u7684\u64cd\u4f5c\u5199\u5230try\u91cc\u662f\u4e3a\u4e86\u81ea\u52a8\u6267\u884cclose\u7684\u5173\u95ed\u6587\u4ef6\u6d41\u7684\u64cd\u4f5c&#xff1b;<\/p>\n<p>\u901a\u8fc7scanner\u6765\u8bfb\u53d6\u5b57\u8282\u6570\u636e&#xff0c;\u7136\u540e\u901a\u8fc7scanner.hashnext\u6765\u5b9e\u73b0\u6ca1\u6709\u8f93\u5165\u65f6\u5c31\u8fdb\u884c\u8df3\u51fa\u5faa\u73af\u64cd\u4f5c&#xff0c;\u8fd9\u91cc\u5c31\u662f\u5ba2\u6237\u7aef\u4e0b\u7ebf\u4e86&#xff1b;<\/p>\n<h5 id=\"4.%E6%95%B0%E6%8D%AE%E7%9A%84%E5%93%8D%E5%BA%94%E7%9A%84%E8%BF%94%E5%9B%9E\">4.\u6570\u636e\u7684\u54cd\u5e94\u7684\u8fd4\u56de<\/h5>\n<p>\u5728\u8fd9\u91cc\u901a\u8fc7\u5b57\u8282\u6570\u636e\u7684\u8bf7\u6c42\u64cd\u4f5c\u5b9e\u73b0\u5bf9\u4e8e\u5ba2\u6237\u7aef\u7684\u54cd\u5e94&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>String request &#061; scanner.next();<br \/>\n                \/\/\u8fdb\u884c\u54cd\u5e94\u64cd\u4f5c<br \/>\n                String response &#061; process(request);<br \/>\n                \/\/\u5c06\u54cd\u5e94\u4f20\u7ed9\u5ba2\u6237\u7aef<br \/>\n                \/\/\u7ed9outputstream\u8fdb\u884c\u5916\u5305\u88c5<br \/>\n                PrintWriter printWriter &#061; new PrintWriter(OutputStream);<br \/>\n                printWriter.println(response); <\/p>\n<p>\u89e3\u91ca&#xff1a;\u8fd9\u91cc\u7684process\u64cd\u4f5c\u5c31\u662f\u76f4\u63a5\u8fd4\u56de\u9700\u6c42\u4f5c\u4e3a\u54cd\u5e94&#xff0c;\u7136\u540e\u8fd9\u91cc\u5c0f\u7f16\u5c31\u901a\u8fc7printwriter\u6765\u5305\u88c5\u4e86outputstream\u8fd9\u4e2a\u5199\u6570\u636e\u7684\u64cd\u4f5c&#xff0c;\u5c31\u662f\u66ff\u4ee3\u4e86\u8fd9\u4e2a\u4ee3\u7801&#xff1a;<\/p>\n<p>OutputStream.write(response.getBytes(),0,response.getBytes().length) <\/p>\n<p>\u8fd9\u91cc\u4e24\u4e2a\u7684\u533a\u522b&#xff1a; OutputStream &#xff1a;\u4f60\u9700\u8981\u5c06\u5b57\u7b26\u4e32\u624b\u52a8\u8f6c\u6362\u4e3a\u5b57\u8282\u6570\u7ec4\u53d1\u9001&#xff0c;\u4f8b\u5982&#xff1b;<\/p>\n<p>String response &#061; &#034;\u6536\u5230\u4f60\u7684\u6d88\u606f&#034;;<br \/>\nbyte[] responseBytes &#061; response.getBytes();<br \/>\noutputStream.write(responseBytes); <\/p>\n<p> PrintWriter &#xff1a;\u5b83\u63d0\u4f9b\u4e86\u66f4\u65b9\u4fbf\u7684\u00a0print\u00a0\u548c\u00a0println\u00a0\u65b9\u6cd5&#xff0c;\u53ef\u4ee5\u76f4\u63a5\u53d1\u9001\u5b57\u7b26\u4e32&#xff1b; \u00a0 \u00a0PrintWriter\u00a0\u4f1a\u81ea\u52a8\u5904\u7406\u5b57\u7b26\u7f16\u7801\u7b49\u7ec6\u8282&#xff0c;\u5e76\u4e14\u5728\u6784\u9020\u51fd\u6570\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4f20\u5165\u00a0true\u00a0\u65f6\u80fd\u591f\u81ea\u52a8\u5237\u65b0\u7f13\u51b2\u533a&#xff0c;\u786e\u4fdd\u6d88\u606f\u53ca\u65f6\u53d1\u9001\u3002\u8fd9\u4f7f\u5f97\u4ee3\u7801\u66f4\u52a0\u7b80\u6d01\u6613\u8bfb&#xff0c;\u51cf\u5c11\u4e86\u56e0\u5b57\u8282\u5904\u7406\u800c\u53ef\u80fd\u4ea7\u751f\u7684\u9519\u8bef\u3002<\/p>\n<h5 id=\"5.%E7%BC%93%E5%86%B2%E5%8C%BA%E7%9A%84%E5%88%B7%E6%96%B0\">5.\u7f13\u51b2\u533a\u7684\u5237\u65b0<\/h5>\n<p>\u8fd9\u91cc\u662fprintwriter\u63d0\u4f9b\u7684\u7f13\u51b2\u533a\u5728\u8fd9\u91cc\u9762\u8fdb\u884c\u4e86\u64cd\u4f5c&#xff0c;\u89e3\u51b3\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p> printWriter.flush();\/\/\u5237\u65b0\u7f13\u51b2\u533a&#xff0c;\u8ba9\u6570\u636e\u53d1\u9001\u51fa\u53bb <\/p>\n<p>\u89e3\u91ca&#xff1a;\u8fd9\u5c31\u662f\u5237\u65b0\u7f13\u51b2\u533a\u7684\u610f\u601d&#xff0c;\u4e3a\u5565\u8981\u5237\u65b0\u7f13\u51b2\u533a\u5462&#xff1f;&#xff1f;&#xff1f;<\/p>\n<p>\u6ce8\u610f&#xff1a;\u8fd9\u91cc\u7684IO\u64cd\u4f5c\u662f\u4e00\u4e2a\u6bd4\u8f83\u4f4e\u6548\u7684\u64cd\u4f5c&#xff0c;\u6240\u4ee5\u5c31\u4f1a\u5c3d\u91cf\u51cf\u5c11\u5bf9\u4e8e\u6587\u4ef6IO\u7684\u64cd\u4f5c&#xff0c;\u6240\u4ee5\u8981\u64cd\u4f5c\u7f51\u5361\u7684\u6570\u636e\u5b58\u653e\u5230\u5185\u5b58\u7f13\u51b2\u533a\u91cc&#xff0c;\u5f53\u79ef\u6512\u5230\u4e00\u5b9a\u7684\u91cf\u540e\u518d\u53d1\u7ed9\u4e0b\u4e00\u5c42\u534f\u8bae<\/p>\n<p>\u00a0\u6240\u4ee5\u5f53\u6570\u636e\u592a\u5c11\u7684\u65f6\u5019&#xff0c;\u5c31\u4f1a\u5b58\u5728\u7f13\u51b2\u533a\u91cc&#xff0c;\u5e76\u6ca1\u6709\u53d1\u9001\u51fa\u53bb&#xff0c;\u6240\u4ee5\u8fd9\u91cc\u8981\u8fdb\u884c\u5237\u65b0\u7684\u64cd\u4f5c&#xff1b;<\/p>\n<h4 id=\"2.3%E5%AE%A2%E6%88%B7%E7%AB%AF%E7%9A%84%E5%AE%9E%E7%8E%B0\">2.3\u5ba2\u6237\u7aef\u7684\u5b9e\u73b0<\/h4>\n<h5>1.\u521d\u59cb\u5316Socket\u7c7b\u5bf9\u8c61<\/h5>\n<p>\u548c\u4e0a\u9762\u7684\u670d\u52a1\u5668\u521d\u59cb\u5316\u662f\u4e00\u81f4\u7684&#xff0c;\u53ea\u4e0d\u8fc7\u4f7f\u7528\u7684\u7c7b\u4e0d\u4e00\u6837&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>public class TcpEchoClient {<br \/>\n    private Socket socket&#061;null;<br \/>\n    public TcpEchoClient(String ServerIP, int ServerPort) throws IOException {<br \/>\n        \/\/\u7531\u4e8etcp\u662f\u6709\u8fde\u63a5\u7684&#xff0c;\u6240\u4ee5\u4f1a\u81ea\u52a8\u4fdd\u5b58\u8fd9\u91cc\u7684ip\u548c\u7aef\u53e3\u53f7<br \/>\n        socket&#061;new Socket(ServerIP,ServerPort);<br \/>\n    } <\/p>\n<p>\u89e3\u91ca&#xff1a;\u8fd9\u91cc\u901a\u8fc7socket\u5bf9\u8c61&#xff0c;\u5b9e\u73b0\u5bf9\u4e8e\u7f51\u5361\u7684\u6a21\u62df\u64cd\u4f5c&#xff0c;\u5728\u6784\u9020\u51fd\u6570\u7684\u65f6\u5019\u5b9a\u4e49\u670d\u52a1\u5668\u7684IP\u5730\u5740\u4ee5\u53ca\u670d\u52a1\u5668\u7684\u7aef\u53e3\u53f7&#xff1b;<\/p>\n<h5 id=\"2.%E5%90%AF%E5%8A%A8%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%B9%B6%E9%98%BB%E5%A1%9E\">2.\u542f\u52a8\u5ba2\u6237\u7aef\u5e76\u963b\u585e<\/h5>\n<p>\u8fd9\u91cc\u5728\u542f\u52a8\u5ba2\u6237\u7aef\u540e\u76f4\u63a5\u8fdb\u5165\u5faa\u73af&#xff0c;\u8fdb\u884c\u4e0d\u65ad\u7684\u4ece\u670d\u52a1\u5668\u8bfb\u53d6\u54cd\u5e94&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>public void start(){<br \/>\n        System.out.println(&#034;\u5ba2\u6237\u7aef\u542f\u52a8\u4e86&#034;);<br \/>\n        try (InputStream inputStream&#061;socket.getInputStream();<br \/>\n             OutputStream outputStream&#061; socket.getOutputStream()){<br \/>\n            Scanner scannerConsole&#061;new Scanner(System.in);<br \/>\n            Scanner scannernetwork&#061;new Scanner(inputStream);<br \/>\n            PrintWriter writer&#061;new PrintWriter(outputStream);<br \/>\n            while (true){<br \/>\n                System.out.println(&#034;-&gt;&#034;);<br \/>\n                if(!scannerConsole.hasNext()){<br \/>\n                    break;<br \/>\n                } <\/p>\n<p>\u89e3\u91ca:\u8fd9\u91cc\u8fd8\u662f\u901a\u8fc7inputstream\u548coutputstream\u6765\u8fdb\u884c\u64cd\u4f5c&#xff0c;\u8fd9\u91cc\u7684\u4e24\u4e2ascanner\u5206\u522b\u7684\u7528\u9014\u5982\u4e0b\u6240\u793a;<\/p>\n<p>\u7b2c\u4e00\u4e2ascanner\u662f\u7528\u4e8e\u5ba2\u6237\u5728\u63a7\u5236\u53f0\u4e0a\u8fdb\u884c\u5b57\u7b26\u4e32\u7684\u8f93\u5165&#xff1b;<\/p>\n<p>\u7b2c\u4e8c\u4e2ascanner\u662f\u7528\u4e8e\u5b57\u8282\u6570\u636e\u7684\u8bfb\u53d6&#xff0c;\u5c31\u662f\u4ece\u670d\u52a1\u5668\u54cd\u5e94\u8fc7\u540e\u7684\u6570\u636e\u63a5\u6536&#xff1b;<\/p>\n<p>\u7b2c\u4e09\u4e2aprintwriter\u7528\u4e8e\u5199\u6570\u636e\u7ed9\u670d\u52a1\u5668&#xff0c;\u8fd9\u91cc\u5c31\u662f\u53d1\u9001\u8bf7\u6c42\u7684\u610f\u601d<\/p>\n<p>\u4e4b\u540e\u8fdb\u5165\u7528\u6237\u7684\u8f93\u5165\u963b\u585e&#xff0c;\u5f53\u4e0d\u8f93\u5165\u65f6&#xff0c;\u5c31\u76f4\u63a5\u8df3\u51fa\u5faa\u73af&#xff0c;\u5ba2\u6237\u7aef\u4e0b\u7ebf&#xff1b;<\/p>\n<h5 id=\"3.%E5%8F%91%E9%80%81%E8%AF%B7%E6%B1%82%E5%92%8C%E6%8E%A5%E6%94%B6%E5%93%8D%E5%BA%94\">3.\u53d1\u9001\u8bf7\u6c42\u548c\u63a5\u6536\u54cd\u5e94<\/h5>\n<p>\u5f53\u6267\u884c\u4e0a\u8ff0\u6b65\u9aa4\u4e4b\u540e&#xff0c;\u6211\u4eec\u5c31\u8981\u6267\u884c\u5bf9\u4e8e\u670d\u52a1\u5668\u6570\u636e\u7684\u53d1\u9001\u8bf7\u6c42\u548c\u63a5\u6536\u54cd\u5e94\u7684\u64cd\u4f5c\u4e86&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p> String request&#061;scannerConsole.next();<br \/>\n                \/\/\u53d1\u9001\u6570\u636e\u7528\u5230\u5199\u7684\u64cd\u4f5c<br \/>\n                writer.println(request);<br \/>\n                writer.flush();<br \/>\n                \/\/\u63a5\u6536\u6570\u636e<br \/>\n                String response&#061;scannernetwork.next();<\/p>\n<p>                System.out.println(response); <\/p>\n<p>\u89e3\u91ca&#xff1a;\u8fd9\u91cc\u5c06\u7528\u6237\u8f93\u5165\u7684\u8bf7\u6c42\u901a\u8fc7writer\u5199\u7ed9\u670d\u52a1\u5668&#xff0c;\u5e76\u5237\u65b0\u4e86\u7f13\u5b58&#xff0c;\u4fdd\u8bc1\u5b57\u8282\u6570\u7ec4\u80fd\u591f\u53d1\u9001\u51fa\u53bb&#xff0c;\u6700\u540e\u901a\u8fc7scannernetwork\u6765\u63a5\u6536\u6570\u636e&#xff0c;\u5e76\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32\u7c7b\u578b\u6570\u636e&#xff0c;\u6700\u540e\u5728\u6253\u5370\u5373\u53ef&#xff1b;<\/p>\n<h5 id=\"4.%E6%96%87%E4%BB%B6%E6%B5%81close%E7%9A%84%E6%93%8D%E4%BD%9C\">4.\u6587\u4ef6\u6d41close\u7684\u64cd\u4f5c<\/h5>\n<p><span style=\"background-color:#ffd900\">1.serversocket<\/span><\/p>\n<p>\u89e3\u91ca&#xff1a;\u7531\u4e8e\u6574\u4e2a\u7a0b\u5e8f\u4e2d\u53ea\u6709\u4e00\u4e2aserversocket\u5bf9\u8c61&#xff0c;\u5e76\u4e14\u8fd9\u4e2a\u5bf9\u8c61\u7684\u751f\u547d\u5468\u671f\u5f88\u957f&#xff0c;\u968f\u7740\u670d\u52a1\u5668\u7684\u9000\u51fa\u81ea\u52a8\u9500\u6bc1&#xff0c;\u6240\u4ee5\u4e0d\u9700\u8981\u8fdb\u884cclose\u64cd\u4f5c&#xff1b;<\/p>\n<p><span style=\"background-color:#ffd900\">2.clientSocket<\/span><\/p>\n<p>\u89e3\u91ca&#xff1a;\u7531\u4e8eclientsocket\u662f\u6bcf\u4e2a\u5ba2\u6237\u7aef\u90fd\u6709\u4e00\u4e2a&#xff0c;\u7531\u4e8e\u8fde\u63a5\u7684\u5ba2\u6237\u7aef\u8d8a\u6765\u8d8a\u591a&#xff0c;\u4e0d\u91ca\u653esocket\u5c31\u4f1a\u5bfc\u81f4\u5c06\u6587\u4ef6\u63cf\u8ff0\u9644\u8868\u5360\u6ee1&#xff0c;\u6240\u4ee5\u8fd9\u91cc\u8981\u8fdb\u884cclose\u7684\u64cd\u4f5c&#xff1b;<\/p>\n<p>\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>finally {<br \/>\n            try {<br \/>\n                clientSocket.close();<br \/>\n            } catch (IOException e) {<br \/>\n                throw new RuntimeException(e);<br \/>\n            }<br \/>\n        } <\/p>\n<p>\u8fd9\u91cc\u5c31\u6dfb\u52a0\u5728\u670d\u52a1\u5668try-catch\u7684\u540e\u9762\u5373\u53ef~~~<\/p>\n<h3 id=\"%F0%9F%93%9A%EF%B8%8F3.%E5%A4%84%E7%90%86%E5%A4%9A%E4%B8%AA%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%90%8C%E6%97%B6%E5%93%8D%E5%BA%94\">&#x1f4da;\ufe0f3.\u5904\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u540c\u65f6\u54cd\u5e94<\/h3>\n<h4 id=\"3.1%E5%90%AF%E5%8A%A8%E5%A4%9A%E4%B8%AA%E6%9C%8D%E5%8A%A1%E5%99%A8\">3.1\u542f\u52a8\u591a\u4e2a\u670d\u52a1\u5668<\/h4>\n<p>\u5f53\u6211\u4eec\u6267\u884c\u4ee3\u7801&#xff0c;\u542f\u52a8\u591a\u4e2a\u670d\u52a1\u5668\u7684\u65f6\u5019\u4f1a\u53d1\u73b0\u6b64\u65f6idea\u4f1a\u7ec8\u6b62\u8fd9\u4e2a\u539f\u6765\u7684\u8fdb\u7a0b&#xff0c;\u7136\u540e\u6267\u884c\u65b0\u7684\u4ee3\u7801&#xff0c;\u5373\u65b0\u7684\u8fdb\u7a0b&#xff0c;\u90a3\u4e48\u89e3\u51b3\u529e\u6cd5\u5982\u4e0b\u6240\u793a&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"360\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418093702-68021d3eb07d7.png\" width=\"294\" \/><\/p>\n<p>\u70b9\u51fb\u540e\u8fdb\u5165\u5982\u4e0b\u7684\u753b\u9762&#xff0c;\u7136\u540e\u8fdb\u5165\u4e00\u4e2a\u65b0\u7684\u754c\u9762\u70b9\u51fb\u5982\u4e0b&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"436\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418093702-68021d3ebf677.png\" width=\"617\" \/><\/p>\n<p>\u7136\u540e\u8fd9\u91cc\u4ee3\u8868\u7684\u5c31\u662f\u5141\u8bb8\u591a\u4e2a\u5b9e\u4f8b\u7684\u8fd0\u884c&#xff0c;\u90a3\u4e48\u5c31\u53ef\u4ee5\u91cd\u590d\u6267\u884c\u4ee3\u7801&#xff0c;\u5b9e\u73b0\u591a\u4e2a\u670d\u52a1\u5668\u540c\u65f6\u8fd0\u884c\u7684\u5b9e\u73b0&#xff1b;<\/p>\n<h4 id=\"3.2%E5%A4%84%E7%90%86%E5%A4%9A%E5%AE%A2%E6%88%B7%E7%AB%AF%E8%AF%B7%E6%B1%82\">3.2\u5904\u7406\u591a\u5ba2\u6237\u7aef\u8bf7\u6c42<\/h4>\n<h5 id=\"1.%E9%97%AE%E9%A2%98%E7%8E%B0%E8%B1%A1\">1.\u95ee\u9898\u73b0\u8c61<\/h5>\n<p>\u6b64\u65f6\u5f53\u6211\u4eec\u5bf9\u7b2c\u4e00\u4e2a\u5ba2\u6237\u7aef\u8fdb\u884c\u8f93\u5165\u7684\u65f6\u5019&#xff0c;\u53d1\u73b0\u6b64\u65f6\u670d\u52a1\u5668\u5bf9\u4e8e\u5ba2\u6237\u7aef\u662f\u6709\u54cd\u5e94\u7684&#xff0c;\u5982\u4e0b\u56fe\u6240\u793a&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"180\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418093702-68021d3ed3524.png\" width=\"555\" \/><\/p>\n<p>\u6b64\u65f6\u662f\u6709\u5ba2\u6237\u7aef\u8f93\u5165\u540e&#xff0c;\u4f1a\u5f97\u5230\u54cd\u5e94\u7684&#xff0c;\u4f46\u662f\u6b64\u65f6\u6211\u4eec\u5bf9\u4e8e\u7b2c\u4e8c\u4e2a\u5ba2\u6237\u7aef\u8fdb\u884c\u6253\u5370\u7684\u65f6\u5019&#xff0c;\u8fd9\u91cc\u662f\u6ca1\u6709\u51fa\u73b0\u54cd\u5e94\u7684&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"99\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418093702-68021d3edfbdd.png\" width=\"552\" \/><\/p>\n<p>\u6b64\u65f6\u6211\u4eec\u53ef\u4ee5\u770b\u89c1\u670d\u52a1\u5668\u5bf9\u4e8e\u4e24\u4e2a\u5ba2\u6237\u7aef\u7684\u4e0a\u7ebf\u72b6\u6001\u4e5f\u662f\u4e0d\u4e00\u6837\u7684&#xff0c;\u5982\u4e0b\u56fe\u6240\u793a&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"139\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418093702-68021d3ee9aa0.png\" width=\"621\" \/><\/p>\n<p>\u5f88\u660e\u663e\u8fd9\u91cc\u5c31\u662f\u53ea\u4e0a\u7ebf\u4e86\u4e00\u4e2a\u5ba2\u6237\u7aef&#xff0c;\u90a3\u4e48\u8fd9\u5c31\u662f\u7b2c\u4e8c\u4e2a\u5ba2\u6237\u7aef\u5f97\u4e0d\u5230\u54cd\u5e94\u7684\u539f\u56e0&#xff1b;<\/p>\n<h5 id=\"2.%E9%97%AE%E9%A2%98%E5%88%86%E6%9E%90\">2.\u95ee\u9898\u5206\u6790<\/h5>\n<p>\u6d41\u7a0b&#xff1a;\u9996\u5148\u8fd9\u91cc\u7684\u670d\u52a1\u5668\u4e3b\u5faa\u73af\u662f\u901a\u8fc7clientsocket\u6765\u8fdb\u884c\u6570\u636e\u8fde\u63a5&#xff0c;\u7136\u540e\u518d\u8fdb\u5165\u6570\u636e\u64cd\u4f5c\u7684\u5faa\u73af&#xff0c;\u5373\u6709\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4&#xff1a;<\/p>\n<p>1.\u8bfb\u53d6\u8bf7\u6c42\u5e76\u4e14\u8fdb\u884c\u89e3\u6790&#xff1b;<\/p>\n<p>2.\u5bf9\u4e8e\u89e3\u6790\u505a\u51fa\u54cd\u5e94&#xff1b;<\/p>\n<p>3.\u5c06\u54cd\u5e94\u4f20\u56de\u7ed9\u5ba2\u6237\u7aef&#xff1b;<\/p>\n<p>\u6ce8\u610f&#xff1a;\u8fd9\u662f\u4e00\u4e2a\u6b7b\u5faa\u73af&#xff0c;\u53ea\u8981\u8fd9\u4e2a\u5faa\u73af\u4e0d\u7ed3\u675f&#xff08;\u5373\u8fde\u63a5\u8fd9\u4e2a\u670d\u52a1\u5668\u7684\u7b2c\u4e00\u4e2a\u5ba2\u6237\u7aef\u4e0d\u7ed3\u675f&#xff09;\u90a3\u4e48\u5c31\u4f1a\u5bfc\u81f4\u670d\u52a1\u5668\u4e00\u76f4\u5728\u8fd9\u4e2a\u5faa\u73af\u7b49\u5f85\u5ba2\u6237\u7aef1\u53f7\u7684\u8bf7\u6c42&#xff0c;\u5e76\u505a\u51fa\u54cd\u5e94&#xff1b;<\/p>\n<p>\u867d\u7136\u8fd9\u91cc\u7b2c\u4e8c\u4e2a\u5ba2\u6237\u7aef\u5b9e\u73b0\u4e86\u5185\u6838\u4e0a\u8fd0\u7528accept\u4e0e\u670d\u52a1\u5668\u5efa\u7acb\u4e86\u8fde\u63a5&#xff0c;\u4f46\u662f\u65e0\u6cd5\u5c06\u8fde\u63a5\u62ff\u5230\u7a0b\u5e8f\u91cc\u8fdb\u884c\u5904\u7406&#xff0c;\u8fd9\u5c31\u662f\u6574\u4e2a\u591a\u5ba2\u6237\u7aef\u00a0\u8bf7\u6c42\u4e0d\u6210\u529f\u7684\u4e3b\u8981\u539f\u56e0&#xff1b;<\/p>\n<h5 id=\"3.%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3\">3.\u95ee\u9898\u89e3\u51b3<\/h5>\n<p><span style=\"background-color:#ffd900\">\u4f7f\u7528\u591a\u7ebf\u7a0b<\/span><\/p>\n<p>\u5bf9\u8fd9\u4e2aprocessClient(Clientsocket)\u6765\u8fdb\u884c\u591a\u4e2a\u7ebf\u7a0b\u5904\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\u4e0e\u54cd\u5e94&#xff0c;\u5177\u4f53\u4ee3\u7801\u5982\u4e0b\u6240\u793a&#xff1a;<\/p>\n<p>while (true) {<br \/>\n            \/\/\u5efa\u7acb\u8fde\u63a5<br \/>\n            Socket Clientsocket &#061; serverSocket.accept();<br \/>\n            Thread t&#061;new Thread(()-&gt;{<br \/>\n                processClient(Clientsocket);<br \/>\n            });<br \/>\n            t.start();<br \/>\n        } <\/p>\n<p>\u89e3\u91ca&#xff1a;\u90a3\u4e48\u6b64\u65f6\u5f53\u7533\u8bf7\u4e00\u4e2a\u5ba2\u6237\u7aef\u7684\u65f6\u5019&#xff0c;\u90a3\u4e48\u5c31\u4f1a\u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\u6765\u5bf9\u8fd9\u4e2a\u5ba2\u6237\u7aef\u8fdb\u884c\u670d\u52a1&#xff0c;\u6b64\u65f6\u5c31\u89e3\u51b3\u4e86\u591a\u5ba2\u6237\u7aef\u8bf7\u6c42\u7684\u95ee\u9898&#xff1b;<\/p>\n<p><span style=\"background-color:#ffd900\">\u4f7f\u7528\u7ebf\u7a0b\u6c60<\/span><\/p>\n<p>\u7531\u4e8e\u4e0a\u8ff0\u7684\u64cd\u4f5c&#xff0c;\u4f1a\u5bfc\u81f4\u4e00\u4e2a\u5ba2\u6237\u7aef\u6267\u884c&#xff0c;\u5c31\u4f1a\u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b&#xff0c;\u4e00\u4e2a\u5ba2\u6237\u7aef\u6267\u884c\u5b8c\u4e86&#xff0c;\u5c31\u4f1a\u9500\u6bc1\u4e00\u4e2a\u7ebf\u7a0b&#xff0c;\u90a3\u4e48\u6b64\u65f6\u5c31\u4f1a\u9020\u6210\u7ebf\u7a0b\u9891\u7e41\u521b\u5efa\u9500\u6bc1\u7684\u5f00\u9500\u589e\u5927&#xff1b;<\/p>\n<p>\u90a3\u4e48\u8fd9\u91cc\u5c31\u5f15\u5165\u4e86\u7ebf\u7a0b\u6c60&#xff0c;\u8fd9\u4e2a\u6982\u5ff5&#xff0c;\u5177\u4f53\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p> while (true) {<br \/>\n            \/\/\u5efa\u7acb\u8fde\u63a5<br \/>\n            Socket Clientsocket &#061; serverSocket.accept();<\/p>\n<p>            ExecutorService pool&#061; Executors.newCachedThreadPool();<br \/>\n            pool.submit(new Runnable() {<br \/>\n                &#064;Override<br \/>\n                public void run() {<br \/>\n                    processClient(Clientsocket);<br \/>\n                }<br \/>\n            });<br \/>\n        } <\/p>\n<p>\u00a0\u89e3\u91ca&#xff1a;\u90a3\u4e48\u6b64\u65f6\u5f53\u521b\u5efa\u597d\u7ebf\u7a0b\u540e&#xff0c;\u5ba2\u6237\u7aef\u6267\u884c&#xff0c;\u90a3\u4e48\u5c31\u4f1a\u4ece\u7ebf\u7a0b\u6c60\u4e2d\u62ff\u4e00\u4e2a\u7ebf\u7a0b\u8fdb\u884c\u670d\u52a1\u5ba2\u6237\u7aef&#xff0c;\u5f53\u5ba2\u6237\u7aef\u6267\u884c\u7ed3\u675f\u540e&#xff0c;\u5c06\u7ebf\u7a0b\u5165\u5230\u7ebf\u7a0b\u6c60&#xff0c;\u5c31\u4e0d\u4f1a\u9500\u6bc1&#xff0c;\u8282\u7701\u4e86\u7ebf\u7a0b\u521b\u5efa\u7684\u5f00\u9500&#xff1b;<\/p>\n<h5 id=\"4.%E6%96%B9%E6%B3%95%E6%89%A9%E5%B1%95\">4.\u65b9\u6cd5\u6269\u5c55<\/h5>\n<p><span style=\"background-color:#ffd900\">\u5f15\u5165\u534f\u7a0b<\/span><\/p>\n<p>\u8fd9\u91cc\u7684\u534f\u7a0b\u5c31\u662f\u8f7b\u91cf\u7ea7\u7ebf\u7a0b&#xff0c;\u7528\u6237\u6001\u53ef\u4ee5\u624b\u52a8\u7684\u8c03\u5ea6\u8fd9\u4e2a\u534f\u7a0b&#xff0c;\u5e76\u53d1\u7684\u6267\u884c\u591a\u4e2a\u5ba2\u6237\u7aef&#xff1b;\u90a3\u4e48\u6b64\u65f6\u7531\u4e8e\u534f\u7a0b\u7684\u521b\u5efa\u548c\u9500\u6bc1\u662f\u7528\u6237\u6001\u8fdb\u884c\u624b\u52a8\u63a7\u5236\u7684&#xff0c;\u6240\u4ee5\u5c31\u7701\u53bb\u4e86\u7cfb\u7edf\u5185\u6838\u7684\u8c03\u5ea6\u5f00\u9500&#xff1b;<\/p>\n<p><span style=\"background-color:#ffd900\">IO\u591a\u8def\u590d\u7528<\/span><\/p>\n<p>IO\u591a\u8def\u590d\u7528&#xff1a;\u8fd9\u91cc\u5c31\u662f\u4e00\u4e2a\u7cfb\u7edf\u5185\u6838\u7ea7\u522b\u7684\u673a\u5236&#xff0c;\u4e3b\u8981\u7684\u5185\u5bb9\u673a\u5236\u5c31\u662f\u4e00\u4e2a\u7ebf\u7a0b\u540c\u65f6\u8d1f\u8d23\u591a\u4e2asocket\u7684\u5904\u7406&#xff1b;<\/p>\n<p>\u672c\u8d28&#xff1a;\u5373\u6bcf\u4e2asocket\u9700\u8981\u64cd\u4f5c\u7684\u6570\u636e\u4e0d\u662f\u540c\u4e00\u65f6\u95f4\u5904\u7406\u7684&#xff1b;<\/p>\n<p>\u4e3e\u4f8b&#xff1a;\u5047\u5982\u6211\u53bb\u4e70\u8857\u4e0a\u4e70\u5403\u7684&#xff0c;\u6211\u53ef\u4ee5\u70b9\u597d\u9910\u540e&#xff0c;\u7b49\u5f85\u540e&#xff0c;\u62ff\u5230\u9910\u4e86&#xff0c;\u90a3\u4e48\u53bb\u4e70\u53e6\u4e00\u4e2a\u4e1c\u897f&#xff1b;\u90a3\u4e48\u6211\u4e5f\u53ef\u4ee5\u7b49\u4e70\u5b8c\u9910\u540e\u76f4\u63a5\u53bb\u4e70\u53e6\u4e00\u4e2a\u4e1c\u897f&#xff0c;\u6b64\u65f6\u5728\u7b49\u8fd9\u4e24\u4e2a\u4e1c\u897f\u5b8c\u6210\u540e&#xff0c;\u518d\u53bb\u62ff&#xff1b;\u8fd9\u91cc\u7684\u672c\u8d28\u5c31\u662f\u6bcf\u4e2a\u4e1c\u897f\u7684\u4e0d\u662f\u540c\u4e00\u4e2a\u65f6\u95f4\u6267\u884c\u7684&#xff1b;<\/p>\n<h3 id=\"%F0%9F%93%9A%EF%B8%8F4.%E6%80%BB%E7%BB%93\">&#x1f4da;\ufe0f4.\u603b\u7ed3<\/h3>\n<p>&#x1f4ac;&#x1f4ac;\u672c\u671f\u5c0f\u7f16\u4e3b\u8981\u8bb2\u89e3\u4e86\u5173\u4e8eTCP\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668\u7684\u64cd\u4f5c\u8fc7\u7a0b\u4e2d&#xff0c;\u670d\u52a1\u5668\u7684\u64cd\u4f5c&#xff0c;\u5ba2\u6237\u7aef\u7684\u64cd\u4f5c&#xff1b;\u4ee5\u53ca\u5982\u4f55\u5904\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u7684\u540c\u65f6\u54cd\u5e94&#xff0c;\u5e76\u8fdb\u884c\u4e86\u95ee\u9898\u7684\u591a\u65b9\u89e3\u51b3~~~<\/p>\n<p><span style=\"color:#38d8f0\">&#x1f305;&#x1f305;&#x1f305;~~~~\u6700\u540e\u5e0c\u671b\u4e0e\u8bf8\u541b\u5171\u52c9&#xff0c;\u5171\u540c\u8fdb\u6b65&#xff01;&#xff01;&#xff01;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"336\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418093703-68021d3f00c20.png\" width=\"450\" \/><\/p>\n<hr \/>\n<p style=\"text-align:center\"><span style=\"color:#38d8f0\">&#x1f4aa;&#x1f4aa;&#x1f4aa;\u4ee5\u4e0a\u5c31\u662f\u672c\u671f\u5185\u5bb9\u4e86&#xff0c; \u611f\u5174\u8da3\u7684\u8bdd&#xff0c;\u5c31\u5173\u6ce8\u5c0f\u7f16\u5427\u3002<\/span><\/p>\n<p style=\"text-align:center\"><span style=\"color:#38d8f0\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&#x1f60a;&#x1f60a; \u00a0\u671f\u5f85\u4f60\u7684\u5173\u6ce8~~~<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb5.9k\u6b21\uff0c\u70b9\u8d5e132\u6b21\uff0c\u6536\u85cf102\u6b21\u3002\u672c\u671f\u4e3b\u8981\u8bb2\u89e3\u4e86\u5173\u4e8eTCP\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668\u7684\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\uff0c\u670d\u52a1\u5668\u7684\u64cd\u4f5c\uff0c\u5ba2\u6237\u7aef\u7684\u64cd\u4f5c\uff1b\u4ee5\u53ca\u5982\u4f55\u5904\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u7684\u540c\u65f6\u54cd\u5e94\uff0c\u5e76\u8fdb\u884c\u4e86\u95ee\u9898\u7684\u591a\u65b9\u89e3\u51b3_java tcp\u670d\u52a1\u7aef\u8fde\u63a5\u591a\u4e2a\u5ba2\u6237\u7aef\u5982\u4f55\u8bc6\u522b\u8fd4\u56de\u6570\u636e\u7ed9\u5bf9\u5e94\u5ba2\u6237\u7aef<\/p>\n","protected":false},"author":2,"featured_media":9715,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[360,358,205,362,361,359,43,78],"topic":[],"class_list":["post-9725","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-io","tag-javaee","tag-tcp-ip","tag-tcpapi","tag-361","tag-359","tag-43","tag-78"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010JavaEE\u521d\u9636\u3011\u7f51\u7edc\u7f16\u7a0bTCP\u534f\u8bae\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668\u4ee5\u53ca\u5982\u4f55\u5904\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u7684\u54cd\u5e94 - \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\/9725.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010JavaEE\u521d\u9636\u3011\u7f51\u7edc\u7f16\u7a0bTCP\u534f\u8bae\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668\u4ee5\u53ca\u5982\u4f55\u5904\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u7684\u54cd\u5e94 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb5.9k\u6b21\uff0c\u70b9\u8d5e132\u6b21\uff0c\u6536\u85cf102\u6b21\u3002\u672c\u671f\u4e3b\u8981\u8bb2\u89e3\u4e86\u5173\u4e8eTCP\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668\u7684\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\uff0c\u670d\u52a1\u5668\u7684\u64cd\u4f5c\uff0c\u5ba2\u6237\u7aef\u7684\u64cd\u4f5c\uff1b\u4ee5\u53ca\u5982\u4f55\u5904\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u7684\u540c\u65f6\u54cd\u5e94\uff0c\u5e76\u8fdb\u884c\u4e86\u95ee\u9898\u7684\u591a\u65b9\u89e3\u51b3_java tcp\u670d\u52a1\u7aef\u8fde\u63a5\u591a\u4e2a\u5ba2\u6237\u7aef\u5982\u4f55\u8bc6\u522b\u8fd4\u56de\u6570\u636e\u7ed9\u5bf9\u5e94\u5ba2\u6237\u7aef\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/9725.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-18T09:37:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418093702-68021d3e20339.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=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/9725.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/9725.html\",\"name\":\"\u3010JavaEE\u521d\u9636\u3011\u7f51\u7edc\u7f16\u7a0bTCP\u534f\u8bae\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668\u4ee5\u53ca\u5982\u4f55\u5904\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u7684\u54cd\u5e94 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T09:37:04+00:00\",\"dateModified\":\"2025-04-18T09:37:04+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/9725.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/9725.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/9725.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010JavaEE\u521d\u9636\u3011\u7f51\u7edc\u7f16\u7a0bTCP\u534f\u8bae\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668\u4ee5\u53ca\u5982\u4f55\u5904\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u7684\u54cd\u5e94\"}]},{\"@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":"\u3010JavaEE\u521d\u9636\u3011\u7f51\u7edc\u7f16\u7a0bTCP\u534f\u8bae\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668\u4ee5\u53ca\u5982\u4f55\u5904\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u7684\u54cd\u5e94 - \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\/9725.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010JavaEE\u521d\u9636\u3011\u7f51\u7edc\u7f16\u7a0bTCP\u534f\u8bae\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668\u4ee5\u53ca\u5982\u4f55\u5904\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u7684\u54cd\u5e94 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb5.9k\u6b21\uff0c\u70b9\u8d5e132\u6b21\uff0c\u6536\u85cf102\u6b21\u3002\u672c\u671f\u4e3b\u8981\u8bb2\u89e3\u4e86\u5173\u4e8eTCP\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668\u7684\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\uff0c\u670d\u52a1\u5668\u7684\u64cd\u4f5c\uff0c\u5ba2\u6237\u7aef\u7684\u64cd\u4f5c\uff1b\u4ee5\u53ca\u5982\u4f55\u5904\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u7684\u540c\u65f6\u54cd\u5e94\uff0c\u5e76\u8fdb\u884c\u4e86\u95ee\u9898\u7684\u591a\u65b9\u89e3\u51b3_java tcp\u670d\u52a1\u7aef\u8fde\u63a5\u591a\u4e2a\u5ba2\u6237\u7aef\u5982\u4f55\u8bc6\u522b\u8fd4\u56de\u6570\u636e\u7ed9\u5bf9\u5e94\u5ba2\u6237\u7aef","og_url":"https:\/\/www.wsisp.com\/helps\/9725.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T09:37:04+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418093702-68021d3e20339.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/9725.html","url":"https:\/\/www.wsisp.com\/helps\/9725.html","name":"\u3010JavaEE\u521d\u9636\u3011\u7f51\u7edc\u7f16\u7a0bTCP\u534f\u8bae\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668\u4ee5\u53ca\u5982\u4f55\u5904\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u7684\u54cd\u5e94 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T09:37:04+00:00","dateModified":"2025-04-18T09:37:04+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/9725.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/9725.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/9725.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010JavaEE\u521d\u9636\u3011\u7f51\u7edc\u7f16\u7a0bTCP\u534f\u8bae\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668\u4ee5\u53ca\u5982\u4f55\u5904\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u7684\u54cd\u5e94"}]},{"@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\/9725","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=9725"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/9725\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/9715"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=9725"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=9725"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=9725"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=9725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}