{"id":27404,"date":"2025-04-19T19:32:40","date_gmt":"2025-04-19T11:32:40","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/27404.html"},"modified":"2025-04-19T19:32:40","modified_gmt":"2025-04-19T11:32:40","slug":"javaee-%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b4-tcp%e5%9b%9e%e6%98%be%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/27404.html","title":{"rendered":"javaEE-\u7f51\u7edc\u7f16\u7a0b4.TCP\u56de\u663e\u670d\u52a1\u5668"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"-toc\" style=\"margin-left:0px\">\n<p id=\"TCP%E6%B5%81%E5%A5%97%E6%8E%A5%E5%AD%97%E7%BC%96%E7%A8%8B-toc\" style=\"margin-left:0px\">TCP\u6d41\u5957\u63a5\u5b57\u7f16\u7a0b<\/p>\n<p id=\"%E4%B8%80.API%E4%BB%8B%E7%BB%8D-toc\" style=\"margin-left:0px\">\u4e00.API\u4ecb\u7ecd<\/p>\n<p id=\"ServerSocket%E7%B1%BB-toc\" style=\"margin-left:40px\">ServerSocket\u7c7b<\/p>\n<p id=\"%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%EF%BC%9A-toc\" style=\"margin-left:80px\">\u6784\u9020\u65b9\u6cd5&#xff1a;<\/p>\n<p id=\"%E2%80%8B%E7%BC%96%E8%BE%91%E6%96%B9%E6%B3%95%EF%BC%9A-toc\" style=\"margin-left:80px\">\u200b\u7f16\u8f91\u65b9\u6cd5&#xff1a;<\/p>\n<p id=\"Socket%E7%B1%BB-toc\" style=\"margin-left:40px\">Socket\u7c7b<\/p>\n<p id=\"%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%EF%BC%9A-toc\" style=\"margin-left:80px\">\u6784\u9020\u65b9\u6cd5&#xff1a;<\/p>\n<p id=\"%E6%96%B9%E6%B3%95%EF%BC%9A-toc\" style=\"margin-left:80px\">\u65b9\u6cd5&#xff1a;<\/p>\n<p id=\"%E4%BA%8C%E3%80%81TCP%E8%BF%9E%E6%8E%A5-toc\" style=\"margin-left:0px\">\u4e8c\u3001TCP\u8fde\u63a5<\/p>\n<p id=\"%E4%B8%89%E3%80%81%E9%80%9A%E8%BF%87TCP%E5%AE%9E%E7%8E%B0%E5%9B%9E%E6%98%BE%E6%9C%8D%E5%8A%A1%E5%99%A8-toc\" style=\"margin-left:0px\">\u4e09\u3001\u901a\u8fc7TCP\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668<\/p>\n<p id=\"TCP%E6%9C%8D%E5%8A%A1%E7%AB%AF%EF%BC%9A-toc\" style=\"margin-left:40px\">TCP\u670d\u52a1\u7aef&#xff1a;<\/p>\n<p id=\"1.%E5%88%9B%E5%BB%BASocket%E5%AF%B9%E8%B1%A1-toc\" style=\"margin-left:80px\">1.\u521b\u5efaSocket\u5bf9\u8c61<\/p>\n<p id=\"2.%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95-toc\" style=\"margin-left:80px\">2.\u6784\u9020\u65b9\u6cd5<\/p>\n<p id=\"3.start%E6%96%B9%E6%B3%95-toc\" style=\"margin-left:80px\">3.start\u65b9\u6cd5<\/p>\n<p id=\"TCP%E5%AE%A2%E6%88%B7%E7%AB%AF%3A-toc\" style=\"margin-left:40px\">TCP\u5ba2\u6237\u7aef:<\/p>\n<p id=\"1.%E5%88%9B%E5%BB%BASocket%E5%AF%B9%E8%B1%A1-toc\" style=\"margin-left:80px\">1.\u521b\u5efaSocket\u5bf9\u8c61<\/p>\n<p id=\"2.%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%3A-toc\" style=\"margin-left:80px\">2.\u6784\u9020\u65b9\u6cd5:<\/p>\n<p id=\"3.start%E6%96%B9%E6%B3%95-toc\" style=\"margin-left:80px\">3.start\u65b9\u6cd5<\/p>\n<p id=\"%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%8F%82%E8%80%83%E4%BB%A3%E7%A0%81%3A-toc\" style=\"margin-left:40px\">\u670d\u52a1\u7aef\u53c2\u8003\u4ee3\u7801:<\/p>\n<p id=\"%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%8F%82%E8%80%83%E4%BB%A3%E7%A0%81%3A-toc\" style=\"margin-left:40px\">\u5ba2\u6237\u7aef\u53c2\u8003\u4ee3\u7801:<\/p>\n<p id=\"%E5%8F%82%E8%80%83%E7%BB%93%E6%9E%9C%3A-toc\" style=\"margin-left:40px\">\u53c2\u8003\u7ed3\u679c:<\/p>\n<hr id=\"hr-toc\" \/>\n<h2 id=\"TCP%E6%B5%81%E5%A5%97%E6%8E%A5%E5%AD%97%E7%BC%96%E7%A8%8B\">TCP\u6d41\u5957\u63a5\u5b57\u7f16\u7a0b<\/h2>\n<h2 id=\"%E4%B8%80.API%E4%BB%8B%E7%BB%8D\">\u4e00.API\u4ecb\u7ecd<\/h2>\n<p>\u6709\u4e24\u4e2a\u5173\u952e\u7684\u7c7b:<\/p>\n<p><span style=\"color:#4da8ee\">ServerSocket<\/span>:\u662f\u521b\u5efaTCP\u670d\u52a1\u7aefSocket\u7684API\u3002\u7ed9\u670d\u52a1\u5668\u4f7f\u7528\u7684\u7c7b,\u4f7f\u7528\u8fd9\u4e2a\u7c7b,\u7ed1\u5b9a\u7aef\u53e3\u53f7.<\/p>\n<p>&#xff08;\u9a6c\u8def\u7259\u5b50\u4e0a\u7684\u62c9\u5ba2\u9500\u552e&#xff09;<\/p>\n<p><span style=\"color:#4da8ee\">Socket<\/span>:\u65e2\u4f1a\u7ed9\u5ba2\u6237\u7aef\u4f7f\u7528&#xff0c;\u53c8\u4f1a\u7ed9\u670d\u52a1\u5668\u4f7f\u7528\u3002\u662f\u5ba2\u6237\u7aef\u7684Socket,\u53c8\u662f\u670d\u52a1\u5668\u63a5\u6536\u5230\u5ba2\u6237\u7aefaccept\u8bf7\u6c42\u540e&#xff0c;\u8fd4\u56de\u7684\u670d\u52a1\u7aefSocket.<\/p>\n<p>(\u552e\u697c\u5904\u7684\u9500\u552e\u987e\u95ee&#xff09;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"71\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113236-680389d4a2ae6.png\" width=\"326\" \/><\/p>\n<h3 id=\"ServerSocket%E7%B1%BB\"><span style=\"color:#38d8f0\">ServerSocket\u7c7b<\/span><\/h3>\n<h4 id=\"%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%EF%BC%9A\">\u6784\u9020\u65b9\u6cd5&#xff1a;<\/h4>\n<h4 id=\"%E2%80%8B%E7%BC%96%E8%BE%91%E6%96%B9%E6%B3%95%EF%BC%9A\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"112\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113236-680389d4c00fb.png\" width=\"1146\" \/>\u65b9\u6cd5&#xff1a;<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"276\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113236-680389d4eb56f.png\" width=\"1147\" \/><\/p>\n<h3 id=\"Socket%E7%B1%BB\"><span style=\"color:#38d8f0\">Socket\u7c7b<\/span><\/h3>\n<p>\u65e2\u4f1a\u7ed9\u5ba2\u6237\u7aef\u4f7f\u7528&#xff0c;\u53c8\u4f1a\u7ed9\u670d\u52a1\u5668\u4f7f\u7528<\/p>\n<p>\u4f5c\u7528&#xff1a;\u53cc\u65b9\u5efa\u7acb\u8fde\u63a5\u540e&#xff0c;\u4fdd\u5b58\u5bf9\u7aef\u4fe1\u606f&#xff0c;\u7528\u6765\u4e0e\u5bf9\u65b9\u6536\u53d1\u6570\u636e\u3002<\/p>\n<h4>\u6784\u9020\u65b9\u6cd5&#xff1a;<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"148\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113237-680389d533b51.png\" width=\"1150\" \/><\/p>\n<h4 id=\"%E6%96%B9%E6%B3%95%EF%BC%9A\">\u65b9\u6cd5&#xff1a;<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"249\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113237-680389d561ce2.png\" width=\"964\" \/><\/p>\n<h2 id=\"%E4%BA%8C%E3%80%81TCP%E8%BF%9E%E6%8E%A5\">\u4e8c\u3001TCP\u8fde\u63a5<\/h2>\n<p>\u5bf9\u4e8eUDP\u6765\u8bf4&#xff0c;\u662f\u65e0\u8fde\u63a5\u7684&#xff0c;\u6bcf\u6b21\u53d1\u9001\u6570\u636e\u65f6&#xff0c;\u90fd\u9700\u8981\u624b\u52a8\u5728send\u65b9\u6cd5\u4e2d\u6307\u5b9a\u76ee\u6807\u5730\u5740&#xff1b;<\/p>\n<p>\u4f46\u662fTCP\u662f\u6709\u8fde\u63a5\u7684&#xff0c;\u9700\u8981\u63d0\u524d\u628a\u8fde\u63a5\u529f\u80fd\u5efa\u7acb\u8d77\u6765&#xff0c;<\/p>\n<p>\u8fde\u63a5\u5982\u4f55\u5efa\u7acb&#xff0c;\u4e0d\u9700\u8981\u4ee3\u7801\u5e72\u9884&#xff0c;\u662f\u7cfb\u7edf\u5185\u6838\u81ea\u52a8\u8d1f\u8d23\u5b8c\u6210\u7684\u3002<\/p>\n<p>\u6211\u4eec\u8981\u505a\u7684\u5c31\u662f&#xff1a;<span style=\"color:#ff9900\">\u5ba2\u6237\u7aef&#xff1a;\u53d1\u8d77\u201c\u5efa\u7acb\u8fde\u63a5\u201d\u7684\u52a8\u4f5c&#xff1b;<\/span><\/p>\n<p><span style=\"color:#ff9900\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u670d\u52a1\u5668&#xff1a;\u628a\u5efa\u7acb\u597d\u7684\u8fde\u63a5\u4ece\u5185\u6838\u4e2d\u62ff\u5230\u5e94\u7528\u7a0b\u5e8f\u91cc\u3002<\/span><\/p>\n<h2 id=\"%E4%B8%89%E3%80%81%E9%80%9A%E8%BF%87TCP%E5%AE%9E%E7%8E%B0%E5%9B%9E%E6%98%BE%E6%9C%8D%E5%8A%A1%E5%99%A8\">\u4e09\u3001\u901a\u8fc7TCP\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668<\/h2>\n<h3 id=\"TCP%E6%9C%8D%E5%8A%A1%E7%AB%AF%EF%BC%9A\"><span style=\"color:#38d8f0\">TCP\u670d\u52a1\u7aef<\/span>&#xff1a;<\/h3>\n<h4 id=\"1.%E5%88%9B%E5%BB%BASocket%E5%AF%B9%E8%B1%A1\">1.\u521b\u5efaSocket\u5bf9\u8c61<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"76\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113237-680389d58f657.png\" width=\"628\" \/><\/p>\n<h4 id=\"2.%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95\">2.\u6784\u9020\u65b9\u6cd5<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"138\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113237-680389d5aff18.png\" width=\"736\" \/><\/p>\n<h4 id=\"3.start%E6%96%B9%E6%B3%95\" style=\"background-color:transparent\">3.start\u65b9\u6cd5<\/h4>\n<p>\u8981\u5faa\u73af\u7684\u8bfb\u53d6\u5ba2\u6237\u7aef\u7684\u8fde\u63a5.\u56e0\u6b64\u8981\u5728\u5faa\u73af\u4e2d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"79\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113237-680389d5d1c09.png\" width=\"412\" \/><\/p>\n<p>\u4efb\u52a11:\u63a5\u542c\u8fde\u63a5,\u901a\u8fc7\u8c03\u7528accept\u65b9\u6cd5<\/p>\n<p>\u4efb\u52a12:\u5efa\u7acb\u8fde\u63a5,\u901a\u8fc7\u5b9e\u73b0processConnection\u65b9\u6cd5,\u5efa\u7acb\u8fde\u63a5<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"181\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113237-680389d5f22c8.png\" width=\"523\" \/><\/p>\n<p><span style=\"color:#fe2c24\">\u4fee\u65391:\u5c06\u8fde\u63a5<\/span><span style=\"color:#fe2c24\">\u6539\u6210\u591a\u7ebf\u7a0b\u6a21\u5f0f<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"127\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113238-680389d620da4.png\" width=\"691\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"178\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113238-680389d642a35.png\" width=\"763\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"85\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113238-680389d6670f7.png\" width=\"367\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"103\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113238-680389d687b8f.png\" width=\"621\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"264\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113238-680389d6a827d.png\" width=\"597\" \/><\/p>\n<p>\u5f53\u591a\u4e2a\u5ba2\u6237\u7aef\u540c\u65f6\u53d1\u51fa\u8bf7\u6c42\u65f6,\u7531\u4e8e\u5355\u7ebf\u7a0b,\u8fd9\u80fd\u5904\u7406\u4e00\u4e2a\u5ba2\u6237\u7aef\u8bf7\u6c42,\u5c06\u8fde\u63a5\u6539\u6210\u591a\u7ebf\u7a0b,\u540c\u65f6\u83b7\u53d6\u591a\u7528\u6237\u7684\u8bf7\u6c42&#xff1b;\u4f46\u662f\u8fd8\u6709\u4e00\u4e2a\u95ee\u9898&#xff0c;\u6bcf\u6765\u4e00\u4e2a\u5ba2\u6237\u7aef&#xff0c;\u5c31\u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b&#xff0c;\u5ba2\u6237\u7aef\u7ed3\u675f&#xff0c;\u5c31\u9500\u6bc1\u8fd9\u4e2a\u7ebf\u7a0b&#xff0c;\u5f53\u591a\u4e2a\u5ba2\u6237\u7aef\u53d1\u8d77\u8bf7\u6c42\u65f6&#xff0c;\u5c31\u8981\u521b\u5efa\u548c\u9500\u6bc1\u5927\u91cf\u7684\u7ebf\u7a0b&#xff0c;\u5f00\u9500\u5c31\u4f1a\u8f83\u5927&#xff1b;<\/p>\n<p>\u53ef\u4ee5\u7528\u7ebf\u7a0b\u6c60\u7684\u65b9\u6cd5\u6765\u521b\u5efa\u591a\u7ebf\u7a0b&#xff0c;\u63d0\u524d\u5c06\u7ebf\u7a0b\u521b\u5efa\u597d&#xff0c;\u9700\u8981\u65f6\u5c31\u76f4\u63a5\u7528&#xff0c;\u4e0d\u7528\u65f6\u5c31\u5148\u653e\u7740&#xff0c;\u4e0d\u9700\u8981\u521b\u5efa\u548c\u9500\u6bc1\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"403\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113238-680389d6cc676.png\" width=\"571\" \/><\/p>\n<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"91\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113239-680389d700ded.png\" width=\"760\" \/><\/p>\n<p>\u7ebf\u7a0b\u6c60\u89e3\u51b3\u4e86\u7ebf\u7a0b\u9891\u7e41\u521b\u5efa\u548c\u9500\u6bc1\u7684\u5f00\u9500&#xff0c;\u4f46\u662f\u5f53\u591a\u4e2a\u7ebf\u7a0b\u88ab\u521b\u5efa&#xff0c;\u800c\u6ca1\u6709\u88ab\u9500\u6bc1&#xff0c;\u5c31\u4f1a\u5bfc\u81f4\u5f53\u524d\u670d\u52a1\u5668\u4e0a\u79ef\u7d2f\u4e86\u7684\u5927\u91cf\u7684\u7ebf\u7a0b&#xff0c;\u8fd9\u5bf9\u4e8e\u670d\u52a1\u5668\u7684\u8d1f\u62c5\u4f1a\u975e\u5e38\u4e25\u91cd\u3002<\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898&#xff0c;\u8fd8\u53ef\u4ee5\u5f15\u5165\u5176\u4ed6\u65b9\u6848&#xff1a;<\/p>\n<p>1\u3001\u5f15\u5165\u534f\u7a0b\u3002&#xff08;\u8f7b\u91cf\u7ea7\u7ebf\u7a0b&#xff09;\u672c\u8d28\u4e0a\u8fd8\u662f\u7ebf\u7a0b&#xff0c;\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u624b\u52a8\u8c03\u5ea6\u7684\u65b9\u6cd5&#xff0c;\u8ba9\u4e00\u4e2a\u7ebf\u7a0b\u5e76\u53d1\u7684\u6267\u884c\u591a\u4e2a\u4efb\u52a1\u3002&#xff08;\u89e3\u51b3\u4e86\u7ebf\u7a0b\u8c03\u5ea6\u7684\u5f00\u9500&#xff09;<\/p>\n<p>2.IO\u591a\u8def\u590d\u7528\u3002&#xff08;\u7cfb\u7edf\u5185\u6838\u7ea7\u522b\u7684\u673a\u5236&#xff09;\u8ba9\u4e00\u4e2a\u7ebf\u7a0b\u8d1f\u8d23\u5904\u7406\u591a\u4e2aSocket\u5bf9\u8c61&#xff0c;\u8fd9\u91cc\u9700\u8981Socket\u6570\u636e\u4e0d\u662f\u540c\u65f6\u9700\u8981\u88ab\u5904\u7406\u7684\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"227\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113239-680389d7224ad.png\" width=\"243\" \/><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"54\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113239-680389d7442a7.png\" width=\"568\" \/><\/p>\n<h4>4.processConnection\u65b9\u6cd5<\/h4>\n<p>\u8f93\u51fa\u5ba2\u6237\u7aefIP\u548c\u7aef\u53e3\u53f7,\u8868\u793a\u5ba2\u6237\u7aef\u4e0a\u7ebf<\/p>\n<h4><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"78\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113239-680389d7647bb.png\" width=\"1162\" \/><\/h4>\n<p>\u901a\u8fc7\u8c03\u7528Socket\u7684getInputStream\u65b9\u6cd5\u83b7\u53d6\u5ba2\u6237\u7aef\u8bf7\u6c42,\u548cgetOutputStream\u8fd4\u56de\u54cd\u5e94<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"79\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113239-680389d78c2f9.png\" width=\"795\" \/><\/p>\n<p>\u4efb\u52a12.1 \u8bfb\u53d6\u5ba2\u6237\u7aef\u8bf7\u6c42<\/p>\n<p>\u8bfb\u53d6\u7ed3\u675f,\u5219\u8868\u660e\u5ba2\u6237\u7aef\u4e0b\u7ebf,\u663e\u793a\u5ba2\u6237\u7aefIP\u548c\u7aef\u53e3\u53f7<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"247\" src=\"2025-04-19pk1lkm3ipnc.png\" width=\"1075\" \/>\u00a0\u00a0\u00a0\u00a02.2,\u8bf7\u6c42\u5e76\u89e3\u6790 \u6ce8\u610f:next\u8bfb\u53d6\u5230\u7a7a\u767d\u5b57\u7b26\u624d\u7ed3\u675f<\/p>\n<p>\u00a0 <img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"85\" src=\"2025-04-19axl3a53fsvn.png\" width=\"519\" \/>\u00a0 \u00a0 \u00a0<\/p>\n<p>\u00a0\u00a0\u00a0\u00a02.3\u6839\u636e\u8bf7\u6c42\u89e3\u6790\u54cd\u5e94<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"73\" src=\"2025-04-19xc532gijr3g.png\" width=\"445\" \/>\u00a0 \u00a0<\/p>\n<p>\u8fd9\u91cc\u7684process\u65b9\u6cd5\u5efa\u8bae\u5199\u6210public,\u65b9\u4fbf\u4e4b\u540e\u5b50\u7c7b\u901a\u8fc7\u7ee7\u627fTcpEchoServer\u65b9\u6cd5,\u5b9e\u73b0\u7279\u6709\u7684\u529f\u80fd<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"136\" src=\"2025-04-19isaibin10gq.png\" width=\"489\" \/><\/p>\n<p>2.4\u628a\u54cd\u5e94\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef, \u901a\u8fc7PrintfWriter\u7684println\u65b9\u6cd5\u8fd4\u56de.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"228\" src=\"2025-04-19ojylyk2nsaj.png\" width=\"1096\" \/><\/p>\n<p><span style=\"color:#fe2c24\">\u4fee\u65392:\u624b\u52a8\u5237\u65b0\u7f13\u51b2\u533a<\/span><\/p>\n<p>\u8fd9\u91cc\u7684println\u4f1a\u6709\u7f13\u51b2\u533a,\u5f53\u8bfb\u53d6\u5230\u5ba2\u6237\u7684\u8bf7\u6c42\u65f6,\u4e0d\u4f1a\u8ba1\u7b97\u54cd\u5e94,\u800c\u662f\u7b49\u7f13\u51b2\u533a\u6ee1\u4e86,\u624d\u4e00\u8d77\u5904\u7406,\u56e0\u6b64,\u6bcf\u6b21\u8bf7\u6c42,\u8981\u624b\u52a8\u5237\u65b0\u7f13\u51b2\u533a,\u624d\u80fd\u4fdd\u8bc1\u5ba2\u6237\u7aef\u7684\u6bcf\u6b21\u8bf7\u6c42\u90fd\u80fd\u53ca\u65f6\u54cd\u5e94<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"100\" src=\"2025-04-19vmnwcnmqkez.png\" width=\"576\" \/><\/p>\n<h3 id=\"TCP%E5%AE%A2%E6%88%B7%E7%AB%AF%3A\"><span style=\"color:#38d8f0\">TCP\u5ba2\u6237\u7aef:<\/span><\/h3>\n<h4>1.\u521b\u5efaSocket\u5bf9\u8c61<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"94\" src=\"2025-04-19uiypwtvscwu.png\" width=\"460\" \/><\/p>\n<h4 id=\"2.%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%3A\">2.\u6784\u9020\u65b9\u6cd5:<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"136\" src=\"2025-04-19xdozij2m3wl.png\" width=\"918\" \/><\/p>\n<h4>3.start\u65b9\u6cd5<\/h4>\n<p>\u56e0\u4e3aTCP\u662f\u4ee5\u5b57\u8282\u6d41\u7684\u5f62\u5f0f\u53d1\u9001\u8bf7\u6c42\u7684,\u8981\u7528InputStream\u6765\u83b7\u53d6\u7528\u6237\u7684\u8f93\u5165; \u83b7\u53d6\u5230\u670d\u52a1\u7aef\u7684\u54cd\u5e94,\u4e5f\u8981\u7528OutputStream\u6765\u63a5\u6536<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"76\" src=\"2025-04-19b1m3cblwn02.png\" width=\"696\" \/><\/p>\n<p>\u4efb\u52a11:\u83b7\u53d6\u7528\u6237\u8f93\u5165\u8bf7\u6c42<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"202\" src=\"2025-04-19c3ljma4vory.png\" width=\"451\" \/><\/p>\n<p>2.\u5c06\u8bf7\u6c42\u53d1\u9001\u7ed9\u670d\u52a1\u7aef \u901a\u8fc7PrintWriter\u7684println\u65b9\u6cd5\u53d1\u9001,\u8fd9\u6837\u53ef\u4ee5\u83b7\u53d6\u5230y\u7528\u6237\u8f93\u5165\u7684 &#034;\\\\n&#034;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"54\" src=\"2025-04-195252wavdpa4.png\" width=\"673\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"85\" src=\"2025-04-19czvrpr4oj3h.png\" width=\"594\" \/><\/p>\n<p><span style=\"color:#fe2c24\">\u4fee\u65391:\u624b\u52a8\u5237\u65b0\u7f13\u51b2\u533a<\/span><\/p>\n<p>\u5ba2\u6237\u7aef\u8fd9\u91cc\u7684println\u4e5f\u6709\u7f13\u51b2\u533a\u7684\u95ee\u9898,\u6bcf\u6b21\u8f93\u5165\u540e,\u4e5f\u8981\u624b\u52a8\u5237\u65b0,\u5c06\u8bf7\u6c42\u53d1\u9001\u7ed9\u670d\u52a1\u7aef<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"111\" src=\"2025-04-19vj1r1bqvhu3.png\" width=\"625\" \/><\/p>\n<p>3.\u4ece\u670d\u52a1\u7aef\u83b7\u53d6\u54cd\u5e94 \u901a\u8fc7Scanner\u8bfb\u53d6OutPutStream\u7684\u8f93\u51fa\u6d41\u6765\u83b7\u53d6\u670d\u52a1\u5668\u8fd4\u56de\u7684\u54cd\u5e94<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"73\" src=\"2025-04-19lke2xshh4yl.png\" width=\"712\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"90\" src=\"2025-04-19wvsomftrep2.png\" width=\"469\" \/><\/p>\n<p>4.\u663e\u793a\u54cd\u5e94<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"79\" src=\"2025-04-19jm4txijnbr2.png\" width=\"372\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"739\" src=\"2025-04-19tkogqezzrmy.png\" width=\"811\" \/><\/p>\n<p><span style=\"color:#fe2c24\">\u4fee\u65392:\u5bf9Socket\u624b\u52a8\u5173\u95ed<\/span><\/p>\n<p>\u76ee\u524d\u8fd9\u4e2a\u4ee3\u7801\u4f1a\u51fa\u73b0\u6587\u4ef6\u8d44\u6e90\u6cc4\u9732,\u521b\u5efa\u7684Socket,\u6ca1\u6709\u8fdb\u884cclose(),<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"159\" src=\"2025-04-19x042m5tauuf.png\" width=\"661\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"154\" src=\"2025-04-19mcvyytd0d2c.png\" width=\"586\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"172\" src=\"2025-04-19xx3p3keezs4.png\" width=\"385\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"73\" src=\"2025-04-19rjia3fucq0v.png\" width=\"712\" \/><\/p>\n<p>\u8fd9\u91cc\u7684\u5173\u95ed,\u53ea\u662f\u5173\u95ed\u4e86\u8f93\u51fa\u6d41\u548c\u8f93\u5165\u6d41,\u5e76\u6ca1\u6709\u5173\u95edSocket<\/p>\n<p>\u56e0\u6b64,\u4e3a\u4e86\u907f\u514d\u6587\u4ef6\u8d44\u6e90\u6cc4\u9732,\u5f53\u5ba2\u6237\u7aef\u65ad\u6765\u8fde\u63a5\u540e,\u8981\u5728\u5ba2\u6237\u7aef\u7684finally\u4ee3\u7801\u5757\u4e2d\u624b\u52a8\u5173\u95ed<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"106\" src=\"2025-04-194rsbprhq0ps.png\" width=\"423\" \/><\/p>\n<h3 id=\"%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%8F%82%E8%80%83%E4%BB%A3%E7%A0%81%3A\">\u670d\u52a1\u7aef\u53c2\u8003\u4ee3\u7801:<\/h3>\n<p>class TcpEchoServer1{<br \/>\n    \/\/\u521b\u5efaServerSocket\u5bf9\u8c61<br \/>\n    private ServerSocket serverSocket&#061;null;<br \/>\n    \/\/\u63d0\u4f9b\u5ba2\u6237\u7aef\u7aef\u53e3\u53f7<br \/>\n    public TcpEchoServer1(int port) throws IOException {<br \/>\n        serverSocket&#061;new ServerSocket(port);<br \/>\n    }<br \/>\n    public void start() throws IOException {<br \/>\n        System.out.println(&#034;\u670d\u52a1\u7aef\u542f\u52a8&#034;);<br \/>\n        ExecutorService pool &#061; Executors.newCachedThreadPool();<br \/>\n        while(true){<br \/>\n            \/\/1.\u901a\u8fc7accpet\u65b9\u6cd5 \u63a5\u542c\u8fde\u63a5<br \/>\n            Socket clientSocket &#061; serverSocket.accept();<br \/>\n            \/\/2.\u901a\u8fc7\u5b9e\u73b0processConnection\u65b9\u6cd5 \u5efa\u7acb\u8fde\u63a5<br \/>\n\/\/            processConnection(clientSocket);<br \/>\n            pool.submit(new Runnable(){\/\/\u901a\u8fc7\u7ebf\u7a0b\u6c60,\u521b\u5efa\u591a\u6761\u7ebf\u7a0b<br \/>\n                &#064;Override<br \/>\n                public void run() {<br \/>\n                    processConnection(clientSocket);<br \/>\n                }<br \/>\n            });<br \/>\n        }<br \/>\n    }<br \/>\n    \/\/TCP\u662f\u4ee5\u5b57\u8282\u6d41\u7684\u65b9\u5f0f\u53d1\u9001\u8bf7\u6c42\u7684,\u8981\u7528InputStream\u6765\u8bfb\u53d6\u53d1\u9001\u7684\u8bf7\u6c42,<br \/>\n                        \/\/    \u7528OutputStream\u6765 \u8fd4\u56de\u54cd\u5e94<br \/>\n    private void processConnection(Socket clientSocket) {<br \/>\n        System.out.printf(&#034;[%s,%d] \u5ba2\u6237\u7aef\u4e0a\u7ebf\\\\n&#034;,clientSocket.getInetAddress(),clientSocket.getPort());<br \/>\n        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\u8fd4\u56de\u54cd\u5e94<br \/>\n           while(true){<br \/>\n               \/\/1.\u8bfb\u53d6\u8bf7\u6c42<br \/>\n               Scanner scan&#061;new Scanner(inputStream);<br \/>\n               if(!scan.hasNext()){<br \/>\n                   \/\/\u8bfb\u53d6\u5b8c\u6bd5,\u5ba2\u6237\u7aef\u65ad\u5f00\u8fde\u63a5,\u4ea7\u751f \u8bfb\u53d6\u5b8c\u6bd5<br \/>\n                   System.out.printf(&#034;[%s,%d] \u5ba2\u6237\u7aef\u4e0b\u7ebf\\\\n&#034;,clientSocket.getInetAddress(),clientSocket.getPort());<br \/>\n                   break;<br \/>\n               }<br \/>\n               \/\/2,\u8bf7\u6c42\u5e76\u89e3\u6790 \u6ce8\u610f:next\u8bfb\u53d6\u5230\u7a7a\u767d\u5b57\u7b26\u624d\u7ed3\u675f<br \/>\n               String request&#061;scan.next();<br \/>\n               \/\/3.\u6839\u636e\u8bf7\u6c42,\u8ba1\u7b97\u54cd\u5e94<br \/>\n               String response&#061;process(request);<br \/>\n               \/\/4.\u628a\u54cd\u5e94\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef<br \/>\n               \/\/\u7ed9outputStream\u5957\u4e0a\u4e00\u5c42,\u53ef\u4ee5\u83b7\u53d6 \\\\n \u66f4\u65b9\u4fbf\u64cd\u4f5c<br \/>\n               PrintWriter printWriter&#061;new PrintWriter(outputStream);<br \/>\n               printWriter.println(response);<br \/>\n               printWriter.flush();\/\/\u624b\u52a8\u5237\u65b0\u7f13\u51b2\u533a<br \/>\n               System.out.printf(&#034;[%s,%d] req:%s, resp:%s\\\\n&#034;,clientSocket.getInetAddress(),clientSocket.getPort(),<br \/>\n                                    request,response);<\/p>\n<p>           }<br \/>\n        } catch (IOException e) {<br \/>\n            throw new RuntimeException(e);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    private String process(String request) {<br \/>\n        \/\/\u8fd9\u91cc\u8fd8\u662f\u4ec0\u4e48\u90fd\u4e0d\u505a,\u5c31\u8fd4\u56de\u8bf7\u6c42<br \/>\n        return request;<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) throws IOException {<br \/>\n        TcpEchoServer1 tcpEchoServer1 &#061; new TcpEchoServer1(9090);<br \/>\n        tcpEchoServer1.start();<br \/>\n    }<br \/>\n} <\/p>\n<h3 id=\"%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%8F%82%E8%80%83%E4%BB%A3%E7%A0%81%3A\">\u5ba2\u6237\u7aef\u53c2\u8003\u4ee3\u7801:<\/h3>\n<p>class TcpEchoClient1{<br \/>\n    \/\/1.\u521b\u5efaSocket\u5bf9\u8c61<br \/>\n    private Socket clientSocket&#061;null;<br \/>\n    \/\/\u4f20\u5165\u670d\u52a1\u7aef\u7684IP\u548c\u7aef\u53e3\u53f7<br \/>\n    public TcpEchoClient1(String serverIp,int serverPort) throws IOException {<br \/>\n        clientSocket&#061;new Socket(serverIp,serverPort);<br \/>\n    }<br \/>\n    public void start() throws IOException {<br \/>\n        System.out.println(&#034;\u5ba2\u6237\u7aef\u542f\u52a8&#034;);<br \/>\n        try(InputStream inputStream&#061;clientSocket.getInputStream();<br \/>\n            OutputStream outputStream&#061;clientSocket.getOutputStream();<br \/>\n            Scanner scanNetWork&#061;new Scanner(inputStream);<br \/>\n            Scanner scanConsole&#061;new Scanner(System.in);<br \/>\n            PrintWriter printWriter&#061;new PrintWriter(outputStream) ) {<\/p>\n<p>            while(true){<br \/>\n                System.out.print(&#034;-&gt;&#034;);<br \/>\n                if(!scanConsole.hasNext()){<br \/>\n                    break;\/\/\u5ba2\u6237\u7aef\u8bf7\u6c42\u8f93\u5165\u7ed3\u675f<br \/>\n                }<br \/>\n                \/\/1.\u83b7\u53d6\u8bf7\u6c42<br \/>\n                String request&#061;scanConsole.next();<br \/>\n                \/\/2.\u5c06\u8bf7\u6c42\u53d1\u9001\u7ed9\u670d\u52a1\u7aef \u901a\u8fc7PrintWriter\u7684println\u65b9\u6cd5\u53d1\u9001<br \/>\n                printWriter.println(request);<br \/>\n                printWriter.flush();<br \/>\n                \/\/3.\u83b7\u53d6\u54cd\u5e94<br \/>\n                String response&#061;scanNetWork.next();<br \/>\n                \/\/4.\u8f93\u51fa\u54cd\u5e94<br \/>\n                System.out.println(response);<br \/>\n            }<br \/>\n        } catch (IOException e) {<br \/>\n            throw new RuntimeException(e);<br \/>\n        }finally {<br \/>\n            clientSocket.close();<br \/>\n        }<br \/>\n    }<br \/>\n    public static void main(String[] args) throws IOException {<br \/>\n        TcpEchoClient1 tcpEchoClient1 &#061; new TcpEchoClient1(&#034;127.0.0.1&#034;, 9090);<br \/>\n        tcpEchoClient1.start();<br \/>\n    }<br \/>\n} <\/p>\n<h3 id=\"%E5%8F%82%E8%80%83%E7%BB%93%E6%9E%9C%3A\" style=\"background-color:transparent\">\u53c2\u8003\u7ed3\u679c:<\/h3>\n<p>\u53ef\u4ee5\u540c\u65f6\u542f\u52a8\u591a\u4e2a\u5ba2\u6237\u7aef,\u4e0e\u540c\u4e00\u4e2a\u670d\u52a1\u7aef\u5efa\u7acb\u8fde\u63a5<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"409\" src=\"2025-04-19c210cuzsg0w.png\" width=\"786\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"379\" src=\"2025-04-19k4xhkqlhlxe.png\" width=\"900\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"423\" src=\"2025-04-19nfh5j5blmou.png\" width=\"754\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"454\" src=\"2025-04-19u2bn4zlfesp.png\" width=\"754\" \/><\/p>\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e11\u6b21\uff0c\u6536\u85cf25\u6b21\u3002\u662f\u521b\u5efaTCP\u670d\u52a1\u7aefSocket\u7684API\u3002\u7ed9\u670d\u52a1\u5668\u4f7f\u7528\u7684\u7c7b,\u4f7f\u7528\u8fd9\u4e2a\u7c7b,\u7ed1\u5b9a\u7aef\u53e3\u53f7.\uff08\u9a6c\u8def\u7259\u5b50\u4e0a\u7684\u62c9\u5ba2\u9500\u552e\uff09:\u65e2\u4f1a\u7ed9\u5ba2\u6237\u7aef\u4f7f\u7528\uff0c\u53c8\u4f1a\u7ed9\u670d\u52a1\u5668\u4f7f\u7528\u3002\u662f\u5ba2\u6237\u7aef\u7684Socket,\u53c8\u662f\u670d\u52a1\u5668\u63a5\u6536\u5230\u5ba2\u6237\u7aefaccept\u8bf7\u6c42\u540e\uff0c\u8fd4\u56de\u7684\u670d\u52a1\u7aefSocket.(\u552e\u697c\u5904\u7684\u9500\u552e\u987e\u95ee\uff09ServerSocket\u7c7b\u3002<\/p>\n","protected":false},"author":2,"featured_media":27384,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[205,43,78],"topic":[],"class_list":["post-27404","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-tcp-ip","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>javaEE-\u7f51\u7edc\u7f16\u7a0b4.TCP\u56de\u663e\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/27404.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"javaEE-\u7f51\u7edc\u7f16\u7a0b4.TCP\u56de\u663e\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e11\u6b21\uff0c\u6536\u85cf25\u6b21\u3002\u662f\u521b\u5efaTCP\u670d\u52a1\u7aefSocket\u7684API\u3002\u7ed9\u670d\u52a1\u5668\u4f7f\u7528\u7684\u7c7b,\u4f7f\u7528\u8fd9\u4e2a\u7c7b,\u7ed1\u5b9a\u7aef\u53e3\u53f7.\uff08\u9a6c\u8def\u7259\u5b50\u4e0a\u7684\u62c9\u5ba2\u9500\u552e\uff09:\u65e2\u4f1a\u7ed9\u5ba2\u6237\u7aef\u4f7f\u7528\uff0c\u53c8\u4f1a\u7ed9\u670d\u52a1\u5668\u4f7f\u7528\u3002\u662f\u5ba2\u6237\u7aef\u7684Socket,\u53c8\u662f\u670d\u52a1\u5668\u63a5\u6536\u5230\u5ba2\u6237\u7aefaccept\u8bf7\u6c42\u540e\uff0c\u8fd4\u56de\u7684\u670d\u52a1\u7aefSocket.(\u552e\u697c\u5904\u7684\u9500\u552e\u987e\u95ee\uff09ServerSocket\u7c7b\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/27404.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-19T11:32:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113236-680389d4a2ae6.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=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/27404.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/27404.html\",\"name\":\"javaEE-\u7f51\u7edc\u7f16\u7a0b4.TCP\u56de\u663e\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-19T11:32:40+00:00\",\"dateModified\":\"2025-04-19T11:32:40+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/27404.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/27404.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/27404.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"javaEE-\u7f51\u7edc\u7f16\u7a0b4.TCP\u56de\u663e\u670d\u52a1\u5668\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"javaEE-\u7f51\u7edc\u7f16\u7a0b4.TCP\u56de\u663e\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/27404.html","og_locale":"zh_CN","og_type":"article","og_title":"javaEE-\u7f51\u7edc\u7f16\u7a0b4.TCP\u56de\u663e\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e11\u6b21\uff0c\u6536\u85cf25\u6b21\u3002\u662f\u521b\u5efaTCP\u670d\u52a1\u7aefSocket\u7684API\u3002\u7ed9\u670d\u52a1\u5668\u4f7f\u7528\u7684\u7c7b,\u4f7f\u7528\u8fd9\u4e2a\u7c7b,\u7ed1\u5b9a\u7aef\u53e3\u53f7.\uff08\u9a6c\u8def\u7259\u5b50\u4e0a\u7684\u62c9\u5ba2\u9500\u552e\uff09:\u65e2\u4f1a\u7ed9\u5ba2\u6237\u7aef\u4f7f\u7528\uff0c\u53c8\u4f1a\u7ed9\u670d\u52a1\u5668\u4f7f\u7528\u3002\u662f\u5ba2\u6237\u7aef\u7684Socket,\u53c8\u662f\u670d\u52a1\u5668\u63a5\u6536\u5230\u5ba2\u6237\u7aefaccept\u8bf7\u6c42\u540e\uff0c\u8fd4\u56de\u7684\u670d\u52a1\u7aefSocket.(\u552e\u697c\u5904\u7684\u9500\u552e\u987e\u95ee\uff09ServerSocket\u7c7b\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/27404.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-19T11:32:40+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250419113236-680389d4a2ae6.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/27404.html","url":"https:\/\/www.wsisp.com\/helps\/27404.html","name":"javaEE-\u7f51\u7edc\u7f16\u7a0b4.TCP\u56de\u663e\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-19T11:32:40+00:00","dateModified":"2025-04-19T11:32:40+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/27404.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/27404.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/27404.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"javaEE-\u7f51\u7edc\u7f16\u7a0b4.TCP\u56de\u663e\u670d\u52a1\u5668"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/27404","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=27404"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/27404\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/27384"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=27404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=27404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=27404"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=27404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}