{"id":17727,"date":"2025-04-19T00:13:18","date_gmt":"2025-04-18T16:13:18","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/17727.html"},"modified":"2025-04-19T00:13:18","modified_gmt":"2025-04-18T16:13:18","slug":"%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b%ef%bc%88udptcp%e5%9b%9e%e6%98%be%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/17727.html","title":{"rendered":"\u7f51\u7edc\u7f16\u7a0b\uff08UDP\\\\TCP\u56de\u663e\u670d\u52a1\u5668\uff09"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"-toc\" style=\"margin-left:0px\">\n<p id=\"%E5%A5%97%E6%8E%A5%E5%AD%97socket-toc\" style=\"margin-left:0px\">\u5957\u63a5\u5b57socket<\/p>\n<p id=\"TCP%E5%92%8CUDP%E7%89%B9%E7%82%B9%E6%AF%94%E8%BE%83%C2%A0-toc\" style=\"margin-left:0px\">TCP\u548cUDP\u7279\u70b9\u6bd4\u8f83\u00a0<\/p>\n<p id=\"%E7%89%B9%E7%82%B9-toc\" style=\"margin-left:40px\">\u7279\u70b9<\/p>\n<p id=\"%E6%AF%94%E8%BE%83-toc\" style=\"margin-left:40px\">\u6bd4\u8f83<\/p>\n<p id=\"UDP%E5%9B%9E%E6%98%BE%E6%9C%8D%E5%8A%A1%E5%99%A8%2F%E5%AE%A2%E6%88%B7%E7%AB%AF%E7%9A%84%E7%BC%96%E5%86%99-toc\" style=\"margin-left:0px\">UDP\u56de\u663e\u670d\u52a1\u5668\/\u5ba2\u6237\u7aef\u7684\u7f16\u5199<\/p>\n<p id=\"UDP%E7%9A%84socket%20api-toc\" style=\"margin-left:40px\">UDP\u7684socket api<\/p>\n<p id=\"%E5%9B%9E%E6%98%BE%E6%9C%8D%E5%8A%A1%E5%99%A8-toc\" style=\"margin-left:40px\">\u56de\u663e\u670d\u52a1\u5668<\/p>\n<p id=\"%E5%AE%A2%E6%88%B7%E7%AB%AF-toc\" style=\"margin-left:40px\">\u5ba2\u6237\u7aef<\/p>\n<p id=\"TCP%E5%9B%9E%E6%98%BE%E6%9C%8D%E5%8A%A1%E5%99%A8%2F%E5%AE%A2%E6%88%B7%E7%AB%AF%E7%9A%84%E7%BC%96%E5%86%99-toc\" style=\"margin-left:0px\">TCP\u56de\u663e\u670d\u52a1\u5668\/\u5ba2\u6237\u7aef\u7684\u7f16\u5199<\/p>\n<p id=\"TCP%E7%9A%84socket%20api-toc\" style=\"margin-left:40px\">TCP\u7684socket api<\/p>\n<p id=\"%E5%9B%9E%E6%98%BE%E6%9C%8D%E5%8A%A1%E5%99%A8-toc\" style=\"margin-left:40px\">\u56de\u663e\u670d\u52a1\u5668<\/p>\n<p id=\"%E5%AE%A2%E6%88%B7%E7%AB%AF-toc\" style=\"margin-left:40px\">\u5ba2\u6237\u7aef<\/p>\n<p id=\"%E4%BC%98%E5%8C%96%E6%9C%8D%E5%8A%A1%E5%99%A8-toc\" style=\"margin-left:0px\">\u4f18\u5316\u670d\u52a1\u5668<\/p>\n<p id=\"1.%E5%85%B3%E9%97%AD%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%88%9B%E5%BB%BA%E7%9A%84socket%E5%AF%B9%E8%B1%A1-toc\" style=\"margin-left:40px\">1.\u5173\u95ed\u670d\u52a1\u5668\u521b\u5efa\u7684socket\u5bf9\u8c61<\/p>\n<p id=\"2.%E5%BC%95%E5%85%A5%E7%BA%BF%E7%A8%8B%E6%B1%A0%EF%BC%8C%E4%B8%BA%E5%A4%9A%E4%B8%AA%E5%AE%A2%E6%88%B7%E7%AB%AF%E6%8F%90%E4%BE%9B%E6%9C%8D%E5%8A%A1%C2%A0-toc\" style=\"margin-left:40px\">2.\u5f15\u5165\u7ebf\u7a0b\u6c60&#xff0c;\u4e3a\u591a\u4e2a\u5ba2\u6237\u7aef\u63d0\u4f9b\u670d\u52a1\u00a0<\/p>\n<hr id=\"hr-toc\" \/>\n<h2 id=\"%E5%A5%97%E6%8E%A5%E5%AD%97socket\">\u5957\u63a5\u5b57socket<\/h2>\n<p>\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7684\u7f51\u7edc\u7f16\u7a0b\u7684API\u79f0\u4e3a\u201csocket api\u201d&#xff0c;\u5728\u4f20\u8f93\u5c42\u4e2d&#xff0c;TCP\u548cUDP\u4e24\u79cd\u534f\u8bae\u7684\u7279\u70b9\u548c\u5dee\u5f02\u975e\u5e38\u5927&#xff0c;\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u5c31\u63d0\u4f9b\u4e86\u4e24\u5957api\u6765\u5206\u522b\u8868\u793a&#xff1a;<\/p>\n<p>\u6d41\u5f0f\u5957\u63a5\u5b57 -&gt; TCP\u4f7f\u7528<\/p>\n<p>\u6570\u636e\u62a5\u5957\u63a5\u5b57 -&gt; UDP\u4f7f\u7528<\/p>\n<p>\u9664\u6b64\u4e4b\u5916\u64cd\u4f5c\u7cfb\u7edf\u8fd8\u6709\u5176\u4ed6\u7684\u5173\u4e8e\u7f51\u7edc\u7f16\u7a0b\u7684API&#xff0c;\u6bd4\u5982Unix\u57df\u5957\u63a5\u5b57&#xff0c;\u53ea\u662f\u672c\u5730\u4e3b\u673a\u4e0a\u7684\u8fdb\u7a0b\u548c\u8fdb\u7a0b\u4e4b\u95f4\u7684\u901a\u4fe1\u65b9\u5f0f&#xff0c;\u4e0d\u80fd\u8de8\u4e3b\u673a\u901a\u4fe1&#xff0c;\u73b0\u5728\u5f88\u5c11\u4f7f\u7528\u3002<\/p>\n<h2 id=\"TCP%E5%92%8CUDP%E7%89%B9%E7%82%B9%E6%AF%94%E8%BE%83%C2%A0\">TCP\u548cUDP\u7279\u70b9\u6bd4\u8f83\u00a0<\/h2>\n<h3 id=\"%E7%89%B9%E7%82%B9\">\u7279\u70b9<\/h3>\n<p>TCP&#xff1a;\u6709\u8fde\u63a5&#xff0c;\u53ef\u9760\u4f20\u8f93&#xff0c;\u9762\u5411\u5b57\u8282\u6d41&#xff0c;\u5168\u53cc\u5de5\u3002<\/p>\n<p>UDP&#xff1a;\u65e0\u8fde\u63a5&#xff0c;\u4e0d\u53ef\u9760\u4f20\u8f93&#xff0c;\u9762\u5411\u6570\u636e\u62a5&#xff0c;\u5168\u53cc\u5de5\u3002<\/p>\n<h3 id=\"%E6%AF%94%E8%BE%83\">\u6bd4\u8f83<\/h3>\n<p><span style=\"background-color:#ffd900\">\u6709\u8fde\u63a5vs\u65e0\u8fde\u63a5<\/span>&#xff1a;<\/p>\n<p>\u6709\u8fde\u63a5\u5219\u662f\u901a\u4fe1\u53cc\u65b9\u4fdd\u5b58\u5bf9\u65b9\u7684\u4fe1\u606f&#xff0c;\u5220\u9664\u4fe1\u606f\u5219\u65ad\u5f00\u8fde\u63a5&#xff0c;\u65e0\u8fde\u63a5\u5219\u662f\u901a\u4fe1\u53cc\u65b9\u4e0d\u9700\u8981\u4fdd\u5b58\u5404\u81ea\u4fe1\u606f\u3002\u5728\u8ba1\u7b97\u673a\u4e2d&#xff0c;\u5404\u81ea\u4fdd\u5b58\u53cc\u65b9\u7684\u4fe1\u606f&#xff0c;\u5c31\u8ba4\u4e3a\u662f\u5efa\u7acb\u4e86\u4e00\u4e2a\u62bd\u8c61\u7684\u8fde\u63a5\u3002<\/p>\n<p><span style=\"background-color:#ffd900\">\u53ef\u9760\u4f20\u8f93vs\u4e0d\u53ef\u9760\u4f20\u8f93<\/span>&#xff1a;<\/p>\n<p>\u53ef\u9760 !&#061; \u5b89\u5168&#xff0c;\u53ef\u9760\u503c\u8981\u4f20\u8f93\u7684\u6570\u5c3d\u53ef\u80fd\u7684\u5168\u90e8\u4f20\u8f93\u7ed9\u5bf9\u65b9&#xff0c;\u5728\u7f51\u7edc\u901a\u4fe1\u8fc7\u7a0b\u4e2d&#xff0c;\u53ef\u80fd\u4f1a\u5b58\u5728\u591a\u79cd\u610f\u5916\u60c5\u51b5&#xff0c;\u6bd4\u5982\u4e22\u5305&#xff0c;\u4e22\u5305\u7684\u8fc7\u7a0b\u662f\u968f\u673a\u7684&#xff0c;\u65e0\u6cd5\u9884\u77e5\u3002\u4e3a\u4e86\u5bf9\u6297\u4e22\u5305&#xff0c;\u5f15\u5165\u4e86\u53ef\u9760\u4f20\u8f93\u7279\u70b9&#xff0c;TCP\u5177\u4f53\u8fd9\u4e00\u7279\u70b9&#xff0c;\u5185\u90e8\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u673a\u5236\u6765\u5b9e\u73b0\u53ef\u9760\u4f20\u8f93&#xff0c;UDP\u5219\u662f\u4e0d\u53ef\u9760\u4f20\u8f93&#xff0c;\u4f20\u8f93\u6570\u636e\u65f6\u4e0d\u4f1a\u5173\u5fc3\u6570\u636e\u662f\u5426\u5230\u8fbe&#xff0c;\u63a5\u6536\u65b9\u662f\u5426\u6536\u5230\u3002\u00a0<\/p>\n<p><span style=\"background-color:#ffd900\">\u9762\u5411\u5b57\u8282\u6d41vs\u9762\u5411\u6570\u636e\u62a5<\/span>:<\/p>\n<p>TCP\u548c\u6587\u4ef6\u64cd\u4f5c\u90fd\u662f\u9762\u5411\u5b57\u8282\u6d41\u7684&#xff0c;\u8bfb\u5199\u64cd\u4f5c\u975e\u5e38\u7075\u6d3b\u3002UDP\u9762\u5411\u6570\u636e\u62a5&#xff0c;\u4f20\u8f93\u7684\u57fa\u672c\u5355\u4f4d\u662f\u4e00\u4e2a\u4e2aUDP\u6570\u636e\u62a5&#xff0c;\u6bcf\u6b21\u8bfb\u5199\u53ea\u80fd\u8bfb\u5199\u4e00\u4e2a\u5b8c\u6574\u7684UDP\u6570\u636e\u62a5\u3002<\/p>\n<p><span style=\"background-color:#ffd900\">\u5168\u53cc\u5de5vs\u7248\u53cc\u5de5<\/span>:<\/p>\n<p>\u5168\u53cc\u5de5&#xff1a;\u4e00\u6761\u94fe\u8def\u80fd\u591f\u8fdb\u884c\u53cc\u5411\u901a\u4fe1&#xff08;TCP\/UDP\u90fd\u662f&#xff09;&#xff0c;\u5728&#xff1b;\u4e00\u6761\u94fe\u8def\u4e0a\u65e2\u53ef\u4ee5\u63a5\u6536\u4e5f\u53ef\u4ee5\u53d1\u9001\u3002<\/p>\n<p>\u534a\u53cc\u5de5&#xff1a;\u4e00\u6761\u94fe\u8def&#xff0c;\u53ea\u80fd\u8fdb\u884c\u5355\u5411\u901a\u4fe1&#xff0c;\u5728Linux\u4e2d&#xff0c;\u7cfb\u7edf\u63d0\u4f9b\u7684\u4e00\u79cd\u8f6f\u4ef6\u8d44\u6e90&#xff1a;\u7ba1\u9053&#xff0c;\u5c31\u662f\u534a\u53cc\u5de5,\u63a5\u6536\u548c\u53d1\u9001\u4e0d\u80fd\u540c\u65f6\u8fdb\u884c\u3002<\/p>\n<h2 id=\"UDP%E5%9B%9E%E6%98%BE%E6%9C%8D%E5%8A%A1%E5%99%A8%2F%E5%AE%A2%E6%88%B7%E7%AB%AF%E7%9A%84%E7%BC%96%E5%86%99\">UDP\u56de\u663e\u670d\u52a1\u5668\/\u5ba2\u6237\u7aef\u7684\u7f16\u5199<\/h2>\n<h3 id=\"UDP%E7%9A%84socket%20api\">UDP\u7684socket api<\/h3>\n<p>java\u5bf9\u4e8e\u7cfb\u7edf\u63d0\u4f9b\u7684\u7f51\u7edc\u7f16\u7a0bapi&#xff08;socket api&#xff09;\u8fdb\u884c\u4e86\u8fdb\u4e00\u6b65\u5c01\u88c5&#xff0c;\u8fdb\u884cUDP\u7f51\u7edc\u7f16\u7a0b\u4ee3\u7801\u7f16\u5199\u65f6&#xff0c;\u9700\u8981\u91cd\u70b9\u7406\u89e3\u4e24\u4e2a\u7c7b&#xff1a;<\/p>\n<p>&#xff08;1&#xff09;DatagramSocket&#xff1a;\u8fd9\u4e2a\u7c7b\u662f\u5bf9\u64cd\u4f5c\u7cfb\u7edfsocket\u6982\u5ff5\u7684\u5c01\u88c5&#xff0c;\u7cfb\u7edf\u4e2d\u7684socket\u53ef\u4ee5\u7406\u89e3\u4e3a\u6587\u4ef6&#xff0c;socket\u6587\u4ef6\u53ef\u4ee5\u89c6\u4e3a\u7f51\u5361\u8fd9\u4e2a\u8bbe\u5907\u7684\u62bd\u8c61\u8868\u793a\u5f62\u5f0f&#xff0c;\u9488\u5bf9socket\u6587\u4ef6\u7684\u8bfb\u5199\u64cd\u4f5c\u8bfe\u76f8\u5f53\u4e8e\u5bf9\u7f51\u5361\u8fd9\u4e2a\u786c\u4ef6\u8bbe\u5907\u8fdb\u884c\u8bfb\u5199\u3002\u5176\u5b9e\u4e4b\u524d\u5b66\u4e60\u7684<span style=\"color:#ff9900\">\u666e\u901a\u6587\u4ef6&#xff0c;\u5c31\u662f\u5bf9\u786c\u76d8\u8fd9\u4e2a\u786c\u4ef6\u8bbe\u5907\u7684\u62bd\u8c61&#xff0c;\u76f4\u63a5\u64cd\u4f5c\u786c\u76d8\u4e0d\u65b9\u4fbf&#xff0c;\u501f\u52a9\u6587\u4ef6\u8fdb\u884c\u64cd\u4f5c\u5c31\u53ef\u4ee5\u5f88\u65b9\u4fbf\u7684\u5b8c\u6210\u3002<\/span>\u7c7b\u4f3c\u4e8e\u7535\u89c6\u673a\u7684\u9065\u63a7\u5668&#xff0c;\u901a\u8fc7\u9065\u63a7\u5668\u6765\u4f7f\u7528\u7535\u89c6\u5267\u66f4\u52a0\u65b9\u4fbf\u3002<\/p>\n<p>\u8ba1\u7b97\u673a\u4e2d\u5bf9\u5177\u6709\u201d\u9065\u63a7\u5c5e\u6027\u201c\u8fd9\u6837\u6982\u5ff5\u7684\u53eb\u505a\u53e5\u67c4&#xff08;handle&#xff09;\u3002<\/p>\n<p>&#xff08;2&#xff09;DatagramPacket&#xff1a;\u9488\u5bf9UDP\u6570\u636e\u62a5\u7684\u62bd\u8c61\u8868\u793a&#xff0c;\u4e00\u4e2aDatagramPacket\u5bf9\u8c61&#xff0c;\u5c31\u76f8\u5f53\u4e0e\u4e00\u4e2aUDP\u6570\u636e\u62a5&#xff0c;\u4e00\u6b21\u53d1\u9001\/\u4e00\u6b21\u63a5\u6536\u5c31\u662f\u4f20\u8f93\u4e86\u4e00\u4e2aDatagramPacket\u5bf9\u8c61\u3002<\/p>\n<h3 id=\"%E5%9B%9E%E6%98%BE%E6%9C%8D%E5%8A%A1%E5%99%A8\">\u56de\u663e\u670d\u52a1\u5668<\/h3>\n<p>Echo\u79f0\u4e3a\u56de\u663e&#xff0c;\u6b63\u5e38\u670d\u52a1\u5668\u53d1\u9001\u4e0d\u540c\u8bf7\u6c42\u5c31\u4f1a\u6709\u4e0d\u540c\u54cd\u5e94&#xff0c;\u56de\u663e\u670d\u52a1\u5668\u5c31\u662f\u8bf7\u6c42\u53d1\u4e86\u4ec0\u4e48&#xff0c;\u54cd\u5e94\u5c31\u662f\u5565&#xff0c;\u8fd9\u4e2a\u8fc7\u7a0b\u4e0d\u6d89\u53ca\u8ba1\u7b97\u548c\u903b\u8f91\u4e1a\u52a1&#xff0c;\u662f\u6700\u7b80\u5355\u7684\u5ba2\u6237\u7aef\u670d\u52a1\u5668\u7a0b\u5e8f\u3002<\/p>\n<p>\u00a0\u7f16\u5199\u670d\u52a1\u5668\u7a0b\u5e8f\u65f6&#xff0c;\u9996\u5148\u9700\u8981\u786e\u5b9a\u7aef\u53e3\u53f7&#xff0c;\u5ba2\u6237\u7aef\u662f\u4e3b\u52a8\u7684\u4e00\u65b9&#xff0c;\u670d\u52a1\u5668\u662f\u88ab\u52a8\u7684\u4e00\u65b9&#xff0c;\u5ba2\u6237\u7aef\u9700\u8981\u627e\u5230\u670d\u52a1\u5668\u5728\u54ea\u3002<\/p>\n<p>IP\u5730\u5740&#xff08;\u670d\u52a1\u5668\u6240\u5728\u4e3b\u673a\u7684IP\u5730\u5740&#xff09;&#xff0c;port\u7aef\u53e3\u53f7&#xff08;\u4e00\u4e2a\u4e3b\u673a\u4e0a&#xff0c;\u6709\u591a\u4e2a\u7a0b\u5e8f\u90fd\u8981\u8fdb\u884c\u7f51\u7edc\u901a\u4fe1&#xff0c;\u9700\u8981\u628a\u90a3\u4e2a\u7a0b\u5e8f\u7528\u7684\u54ea\u4e2a\u7aef\u53e3\u53f7\u8bb0\u5f55\u4e0b\u6765&#xff0c;\u5e76\u8981\u786e\u4fdd\u4e00\u4e2a\u7aef\u53e3\u53f7\u4e0d\u80fd\u88ab\u4e24\u4e2a\u6216\u591a\u4e2a\u8fdb\u7a0b\u5173\u8054&#xff09;\u3002<\/p>\n<p>import java.io.IOException;<br \/>\nimport java.net.DatagramSocket;<\/p>\n<p>public class UdppEchoServer {<br \/>\n    private DatagramSocket socket &#061; null;<br \/>\n    public UdppEchoServer(int port) throws IOException {<br \/>\n        socket &#061; new DatagramSocket(port);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u629b\u51fa\u7684\u4e00\u5f02\u5e38\u53ef\u4ee5\u662fIOException&#xff0c;\u4e5f\u5c31\u662f\u8bf4\u660e\u7f51\u7edc\u7f16\u7a0b\u7684\u672c\u8d28\u662fIO\u64cd\u4f5c\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u8981\u8ba9\u670d\u52a1\u5668\u53ef\u4ee5\u4e0d\u505c\u7684\u5904\u7406\u8bf7\u6c42&#xff0c;\u4e0d\u505c\u7684\u8fd4\u56de\u54cd\u5e94&#xff1a;<\/p>\n<p><span style=\"color:#fe2c24\">\u7b2c\u4e00\u6b65&#xff1a;\u8bfb\u53d6\u8bf7\u6c42\u5e76\u5bf9\u8bf7\u6c42\u8fdb\u884c\u89e3\u6790<\/span>&#xff0c;\u6784\u9020\u4e00\u4e2a\u6570\u636e\u62a5\u7c7b\u7684\u5b9e\u4f8b&#xff0c;\u5bf9\u5ba2\u6237\u7aef\u53d1\u9001\u7684\u6570\u636e\u8fdb\u884c\u63a5\u6536&#xff0c;\u653e\u5165\u5b9e\u4f8b\u4e2d&#xff0c;\u5bf9\u6570\u636e\u8fdb\u884c\u89e3\u6790,\u6700\u540e\u4e3a\u4e86\u65b9\u4fbf\u6253\u5370&#xff0c;\u5c06\u6570\u636e\u62a5\u4e2d\u7684\u4e8c\u8fdb\u5236\u6570\u62ff\u51fa\u6765&#xff0c;\u8f6c\u6362\u4e3aString\u7c7b\u578b\u7684\u6570\u636e&#xff0c;String\u6709\u4e00\u4e2a\u6784\u9020\u65b9\u6cd5&#xff0c;\u901a\u8fc7\u5b57\u8282\u6570\u7ec4\u6765\u6784\u9020\u3002<\/p>\n<p> DatagramPacket requestPacket &#061; new DatagramPacket(new byte[4096],4096);<br \/>\n socket.receive(requestPacket);<br \/>\n String  request &#061; new String(requestPacket.getData(),0, requestPacket.getLength()); <\/p>\n<p><span style=\"color:#fe2c24\">\u7b2c\u4e8c\u6b65&#xff1a;\u6839\u636e\u8bf7\u6c42\u8fd4\u56de\u54cd\u5e94<\/span>&#xff0c;\u7531\u4e8e\u662f\u56de\u663e\u670d\u52a1\u5668&#xff0c;\u8ba1\u7b97\u8bf7\u6c42\u7684\u65b9\u6cd5\u76f4\u63a5\u8fd4\u56de\u5c31\u884c&#xff0c;\u8fd4\u56de\u7684\u54cd\u5e94\u4f7f\u7528String\u8fdb\u884c\u63a5\u6536\u3002<\/p>\n<p>String response &#061; process(request);<br \/>\npublic String process(String request) {<br \/>\n       return request;<br \/>\n} <\/p>\n<p><span style=\"color:#fe2c24\">\u7b2c\u4e09\u6b65&#xff1a;\u5c06\u54cd\u5e94\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef<\/span>&#xff0c;\u53d1\u9001\u65f6\u9700\u8981\u77e5\u9053\u63a5\u6536\u5bf9\u8c61\u7684IP\u548c\u7aef\u53e3\u53f7&#xff0c;\u53ef\u4ee5\u901a\u8fc7\u63a5\u6536\u7684UDP\u6570\u636e\u62a5\u62ff\u5230\u53d1\u9001\u5ba2\u6237\u7aef\u7684\u4fe1\u606f&#xff0c;\u62ff\u5230\u4e4b\u540e\u653e\u5230\u54cd\u5e94\u7684\u6570\u636e\u62a5\u4e2d\u4f7f\u7528send()\u65b9\u6cd5\u53d1\u9001&#xff0c;\u6700\u540e\u5728\u670d\u52a1\u5668\u4e0a\u9762\u6253\u5370\u5173\u952e\u4fe1\u606f\u3002<\/p>\n<p>\/\/\u628a\u54cd\u5e94\u5199\u56de\u5230\u5ba2\u6237\u7aef<br \/>\n\/\/\u6784\u9020UDP\u6570\u636e\u5305<br \/>\nDatagramPacket responsePacket &#061; new DatagramPacket(response.getBytes(),0,response.getBytes().length,<br \/>\n                requestPacket.getSocketAddress());<br \/>\n\/\/\u53d1\u9001\u8bf7\u6c42\u5230\u5ba2\u6237\u7aef<br \/>\n socket.send(responsePacket);<br \/>\n System.out.printf(&#034;[%s %d] req &#061; %s, resp &#061;%s\\\\n&#034;,requestPacket.getAddress(),requestPacket.getPort(),request,response); <\/p>\n<p>\u8ba9\u7a0b\u5e8f\u542f\u52a8\u540e\u4e0d\u65ad\u8fd0\u884c&#xff0c;\u52a0\u4e0awhile\u5faa\u73af&#xff0c;\u4e00\u4e2a\u5b8c\u6574\u7684UDP\u56de\u663e\u670d\u52a1\u5668\u5c31\u6b64\u5b8c\u6210\u4e86\u3002<\/p>\n<\/p>\n<h3 id=\"%E5%AE%A2%E6%88%B7%E7%AB%AF\">\u5ba2\u6237\u7aef<\/h3>\n<p>\u5ba2\u6237\u7aef\u9700\u8981\u6709\u81ea\u5df1\u7684\u7aef\u53e3\u53f7\u548cip\u5730\u5740&#xff0c;\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u5728\u4e00\u53f0\u4e3b\u673a\u4e0a\u65f6\u5c31\u53ef\u4ee5\u5199\u672c\u5730\u73af\u56de\u5730\u5740&#xff08;127.0.0.1&#xff09;&#xff0c;\u7aef\u53e3\u53f7\u662f\u670d\u52a1\u5668\u5728\u521b\u5efasocket\u65f6\u6307\u5b9a\u7684\u7aef\u53e3\u53f7\u3002<\/p>\n<p>public class UdpEchoClient {<br \/>\n    private DatagramSocket socket &#061; null;<br \/>\n    private String serverPort;<br \/>\n    private String serverIP;<br \/>\n    public UdpEchoClient(String serverPort,String serverIP) throws SocketException {<br \/>\n        socket &#061; new DatagramSocket();<br \/>\n        this.serverPort &#061; serverPort;<br \/>\n        this.serverIP &#061; serverIP;<br \/>\n    }<br \/>\n} <\/p>\n<p>\u00a0\u5728\u521b\u5efasocket\u5bf9\u8c61\u65f6\u5e76\u6ca1\u6709\u6307\u5b9a\u7aef\u53e3\u53f7&#xff0c;\u8fd9\u662f\u56e0\u4e3a\u64cd\u4f5c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u5206\u914d\u4e00\u4e2a\u7aef\u53e3\u53f7&#xff0c;\u8fd9\u4e2a\u81ea\u52a8\u7684\u7aef\u53e3\u53f7\u6bcf\u6b21\u91cd\u542f\u90fd\u4f1a\u4e0d\u4e00\u6837\u3002<\/p>\n<p>\u670d\u52a1\u5668\u9700\u8981\u56fa\u5b9a\u7aef\u53e3\u53f7&#xff0c;\u800c\u5ba2\u6237\u7aef\u9700\u8981\u8ba9\u7cfb\u7edf\u81ea\u52a8\u5206\u914d&#xff1a;<\/p>\n<p>&#xff08;1&#xff09;\u670d\u52a1\u5668\u8981\u6709\u56fa\u5b9a\u7aef\u53e3\u53f7&#xff0c;\u662f\u56e0\u4e3a\u5ba2\u6237\u7aef\u9700\u8981\u4e3b\u52a8\u7ed9\u670d\u52a1\u5668\u53d1\u8bf7\u6c42&#xff0c;\u5982\u679c\u670d\u52a1\u5668\u7aef\u53e3\u53f7\u4e0d\u662f\u56fa\u5b9a\u7684&#xff0c;\u5ba2\u6237\u7aef\u5c31\u4f1a\u4e0d\u77e5\u9053\u628a\u8bf7\u6c42\u53d1\u7ed9\u8c01\u4e86\u3002<\/p>\n<p>&#xff08;2&#xff09;\u5ba2\u6237\u7aef\u9700\u8981\u7cfb\u7edf\u81ea\u52a8\u5206\u914d&#xff0c;\u6307\u5b9a\u56fa\u5b9a\u7684\u7aef\u53e3\u53f7\u662f\u4e0d\u884c\u7684&#xff0c;\u6307\u5b9a\u5ba2\u6237\u7aef\u7684\u7aef\u53e3\u53f7&#xff0c;\u53ef\u80fd\u4f1a\u548c\u5ba2\u6237\u7aef\u6240\u5728\u7535\u8111\u4e0a\u7684\u5176\u4ed6\u7a0b\u5e8f\u51b2\u7a81&#xff0c;\u4e00\u65e6\u7aef\u53e3\u51b2\u7a81&#xff0c;\u5c31\u4f1a\u5bfc\u81f4\u7a0b\u5e8f\u542f\u52a8\u4e0d\u4e86\u3002\u670d\u52a1\u5668\u5728\u81ea\u5df1\u624b\u91cc&#xff0c;\u5c31\u7b97\u7aef\u53e3\u51b2\u7a81\u4e5f\u662f\u53ef\u4ee5\u8c03\u6574\u7684&#xff0c;\u4f46\u5ba2\u6237\u7aef\u4e0d\u5728\u672c\u673a\u4e0a\u65f6&#xff0c;\u7aef\u53e3\u51b2\u7a81\u96be\u4ee5\u89e3\u51b3\u3002<\/p>\n<p>\u5ba2\u6237\u7aef\u903b\u8f91\u5728\u7f16\u5199\u65f6\u548c\u670d\u52a1\u5668\u6709\u76f8\u540c\u4e4b\u5904&#xff0c;\u5ba2\u6237\u7aef\u53d1\u9001\u8bf7\u6c42\u5230\u670d\u52a1\u5668\u540e&#xff0c;\u4f7f\u7528UDP\u6570\u636e\u62a5\u6765\u63a5\u53d7\u54cd\u5e94\u3002<\/p>\n<p>import java.io.IOException;<br \/>\nimport java.net.*;<br \/>\nimport java.util.Scanner;<br \/>\npublic class UdpEchoClient {<br \/>\n    private DatagramSocket socket &#061; null;<br \/>\n    private int serverPort;<br \/>\n    private String serverIP;<br \/>\n    public UdpEchoClient(String serverIP,int serverPort) throws SocketException {<br \/>\n        socket &#061; new DatagramSocket();<br \/>\n        this.serverPort &#061; serverPort;<br \/>\n        this.serverIP &#061; serverIP;<br \/>\n    }<br \/>\n    public void start() throws IOException {<br \/>\n        System.out.println(&#034;\u5ba2\u6237\u7aef\u542f\u52a8&#034;);<br \/>\n        Scanner scanner &#061; new Scanner(System.in);<br \/>\n        while (true) {<br \/>\n           \/\/\u8f93\u5165\u8bf7\u6c42<br \/>\n            System.out.println(&#034;\u8bf7\u8f93\u5165\u8bf7\u6c42: &#034;);<br \/>\n            String request &#061; scanner.next();<br \/>\n            \/\/\u6784\u9020\u8bf7\u6c42<br \/>\n            DatagramPacket requestPacket &#061; new DatagramPacket(request.getBytes(),0,request.getBytes().length,<br \/>\n                    InetAddress.getByName(serverIP),serverPort);<br \/>\n            \/\/\u53d1\u9001\u8bf7\u6c42<br \/>\n            socket.send(requestPacket);<br \/>\n            \/\/\u6784\u9020\u63a5\u6536\u7684\u6570\u636e\u62a5<br \/>\n            DatagramPacket responsePack &#061; new DatagramPacket(new byte[4096],4096);<br \/>\n            \/\/\u63a5\u6536\u670d\u52a1\u5668\u8fd4\u56de\u7684\u7ed3\u679c<br \/>\n            socket.receive(responsePack);<br \/>\n            \/\/\u8f6c\u6362\u6210String\u7c7b\u578b<br \/>\n            String response &#061; new String(responsePack.getData(),0, responsePack.getLength());<br \/>\n            System.out.println(response);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) throws IOException {<br \/>\n        UdpEchoClient udpEchoClient &#061; new UdpEchoClient(&#034;127.0.0.1&#034;,9090);<br \/>\n        udpEchoClient.start();<br \/>\n    }<br \/>\n} <\/p>\n<p>\u00a0\u670d\u52a1\u5668\u4e0e\u5ba2\u6237\u7aef\u540c\u65f6\u542f\u52a8&#xff0c;\u5ba2\u6237\u7aef\u53d1\u9001\u6d88\u606f&#xff0c;\u670d\u52a1\u5668\u90fd\u4f1a\u56de\u663e\u56de\u6765&#xff0c;\u5e76\u5728\u63a7\u5236\u53f0\u6253\u5370\u76f8\u5e94\u7684ip\u5730\u5740&#xff0c;\u7aef\u53e3\u53f7&#xff0c;\u8bf7\u6c42\u548c\u54cd\u5e94&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"748\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418161317-68027a1d02060.png\" width=\"1200\" \/><\/p>\n<h2 id=\"TCP%E5%9B%9E%E6%98%BE%E6%9C%8D%E5%8A%A1%E5%99%A8%2F%E5%AE%A2%E6%88%B7%E7%AB%AF%E7%9A%84%E7%BC%96%E5%86%99\">TCP\u56de\u663e\u670d\u52a1\u5668\/\u5ba2\u6237\u7aef\u7684\u7f16\u5199<\/h2>\n<h3 id=\"TCP%E7%9A%84socket%20api\">TCP\u7684socket api<\/h3>\n<p>\u4e3b\u8981\u6d89\u53ca\u4e24\u4e2a\u7c7b&#xff1a;ServerSocket\u548cSocket\u3002<\/p>\n<p>ServerSocket\u662f\u4e13\u95e8\u63d0\u4f9b\u7ed9\u670d\u52a1\u5668\u4f7f\u7528\u7684&#xff0c;ServerSocket\u5728 \u5b9e\u4f8b\u5316\u65f6\u8c03\u7528\u7684\u6784\u9020\u65b9\u6cd5\u4e2d\u81ea\u5e26\u7aef\u53e3\u53f7&#xff0c;\u5b9e\u4f8b\u5316\u7684\u5bf9\u8c61\u5305\u542b\u4e00\u4e2aaccept\u65b9\u6cd5&#xff0c;\u662f\u4e00\u4e2a\u7c7b\u4f3c\u63a5\u901a\u529f\u80fd\u7684\u65b9\u6cd5\u3002<\/p>\n<p>Socket\u662f\u7ed9\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u90fd\u63d0\u4f9b\u670d\u52a1&#xff0c;\u901a\u8fc7Socket\u7684\u6784\u9020\u65b9\u6cd5\u80fd\u591f\u548c\u6307\u5b9a\u7684\u670d\u52a1\u5668\u5efa\u7acb\u8fde\u63a5\u3002<\/p>\n<p>TCP\u4e2d\u901a\u8fc7\u4f7f\u7528InputStream\u548cOutputStream\u8fdb\u884c\u6587\u4ef6\u8bfb\u5199\u64cd\u4f5c&#xff0c;\u901a\u8fc7\u4e24\u4e2aget\u65b9\u6cd5\u6765\u83b7\u53d6socket\u5185\u90e8\u6d41\u5bf9\u8c61\u3002<\/p>\n<p>Socket socket &#061; new Socket();<br \/>\nsocket.getInputStream();<br \/>\nsocket.getOutputStream(); <\/p>\n<p>Tcp\u662f\u5b57\u8282\u6d41\u4f20\u8f93&#xff0c;\u4f20\u8f93\u57fa\u672c\u5355\u4f4d\u662f\u5b57\u8282\u3002<\/p>\n<p>ServerSocket\u548cSocket\u7684\u529f\u80fd\u4e0d\u540c&#xff1a;\u5bf9\u4e8e\u670d\u52a1\u5668\u6765\u8bf4&#xff0c;\u9700\u8981\u4e0a\u6765\u4e0e\u5ba2\u6237\u7aef\u5efa\u7acb\u8fde\u63a5&#xff0c;\u5efa\u7acb\u8fde\u63a5\u8981\u4f7f\u7528ServerSocket\u5bf9\u8c61\u7684accept\u65b9\u6cd5&#xff0c;\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u4e3asocket\u7c7b\u578b&#xff1b;\u670d\u52a1\u5668\u4e00\u542f\u52a8\u5c31\u4f1a\u6267\u884c\u5230\u5efa\u7acb\u8fde\u63a5\u7684\u4f4d\u7f6e&#xff0c;\u5982\u679c\u6b64\u65f6\u6ca1\u6709\u5ba2\u6237\u7aef\u8fde\u63a5\u90a3\u4e48accept\u65b9\u6cd5\u5c31\u4f1a\u8fdb\u5165\u963b\u585e\u72b6\u6001&#xff0c;\u76f4\u5230\u6709\u5ba2\u6237\u7aef\u8fde\u63a5\u3002\u4e5f\u5c31\u662f\u8bf4&#xff0c;ServerSocket\u662f\u7528\u4e0e\u5efa\u7acb\u8fde\u63a5\u4f7f\u7528\u7684&#xff0c;\u8fde\u63a5\u540e\u5c06socket\u5bf9\u8c61\u4ea4\u7ed9socket\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<h3>\u56de\u663e\u670d\u52a1\u5668<\/h3>\n<p>\u00a0\u6bcf\u6b21\u521b\u5efa\u4e00\u4e2a\u670d\u52a1\u5668\u5bf9\u8c61\u90fd\u8981\u521b\u5efa\u4e00\u4e2aSerrverSocket\u6765\u8fde\u63a5\u5ba2\u6237\u7aef&#xff0c;\u521b\u5efa\u670d\u52a1\u5668\u65f6\u8981\u5305\u542b \u7aef\u53e3\u53f7&#xff0c;\u5426\u5219\u5ba2\u6237\u7aef\u6ca1\u6709\u7aef\u53e3\u53f7\u5c31\u65e0\u6cd5\u8fde\u63a5\u3002<\/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);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u00a0\u5728\u670d\u52a1\u5668\u4e2d\u521b\u5efastart\u65b9\u6cd5\u7528\u6765\u542f\u52a8\u670d\u52a1\u5668&#xff0c;\u8c03\u7528start\u65b9\u6cd5\u540e\u670d\u52a1\u5668\u5f00\u59cb\u4e0d\u65ad\u7684\u6267\u884c\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42&#xff0c;\u4e0d\u505c\u7684\u5904\u7406\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\u5c31\u9700\u8981\u4e0d\u505c\u7684\u4e0e\u5ba2\u6237\u7aef\u5efa\u7acb\u8fde\u63a5&#xff0c;\u901a\u8fc7\u8c03\u7528process()\u65b9\u6cd5\u53bb\u5904\u7406\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42&#xff0c;\u5c06\u548c\u5ba2\u6237\u7aef\u5efa\u7acb\u8fde\u63a5\u7684\u4fe1\u606f\u4f7f\u7528socket\u63a5\u6536&#xff0c;\u4f20\u9012\u7ed9process\u65b9\u6cd5&#xff1a;<\/p>\n<p>public void start() throws IOException {<br \/>\n        System.out.println(&#034;\u670d\u52a1\u5668\u542f\u52a8&#034;);<br \/>\n        while (true) {<br \/>\n            Socket socket &#061; serverSocket.accept();<br \/>\n            possess(socket);<br \/>\n        }<br \/>\n    } <\/p>\n<p>\u00a0\u5b9e\u73b0process\u65b9\u6cd5&#xff0c;\u8981\u6ce8\u610fTCP\u662f\u9762\u5411\u5b57\u8282\u6d41\u4f20\u8f93&#xff0c;\u6b64\u65f6\u8fdb\u884c\u8bfb\u5199\u64cd\u4f5c\u65f6\u9700\u8981\u4f7f\u7528InputStream\u548cOutputStream&#xff0c;\u8fd9\u4e24\u4e2a\u7c7b\u5728\u4f7f\u7528\u5b8c\u540e\u5fc5\u987b\u56de\u6536\u9632\u6b62\u8d44\u6e90\u6cc4\u9732&#xff0c;\u907f\u514d\u6570\u636e\u4e22\u5931&#xff0c;\u4f7f\u7528 try-catch\u65b9\u6cd5\u91cc\u7684try with source\u7528\u6cd5&#xff0c;\u628a\u5bf9\u8c61\u653e\u5230try()\u4e2d&#xff0c;\u4f7f\u7528 \u5b8c\u6bd5\u4f1a\u81ea\u52a8\u56de\u6536\u8d44\u6e90\u3002\u83b7\u5f97\u6570\u636e\u540e\u53ef\u4ee5\u4f7f\u7528Read\u7c7b\u8bfb\u53d6\u8bf7\u6c42&#xff0c;\u4f46\u662fRead\u7c7b\u8bfb\u53d6\u8bf7\u6c42\u540e\u5f97\u5230\u7684\u662fbyte\u6570\u7ec4&#xff0c;\u9700\u8981\u8fdb\u4e00\u6b65\u8f6c\u6362\u6210\u5b57\u7b26\u4e32 &#xff0c;\u8fd9\u91cc\u4f7f\u7528Scanner\u53bb\u8bfb\u53d6\u53ef\u4ee5\u76f4\u63a5\u8f6c\u6362\u6210String\u7c7b\u578b&#xff1a;<\/p>\n<p>    private void possess(Socket clientSocket)  {<br \/>\n        System.out.println(&#034;\u5ba2\u6237\u7aef\u4e0a\u7ebf&#034;);<br \/>\n        try(InputStream inputStream &#061; clientSocket.getInputStream();<br \/>\n            OutputStream outputStream &#061; clientSocket.getOutputStream()) {<br \/>\n            Scanner scanner &#061; new Scanner(inputStream);<br \/>\n            while (true) {<br \/>\n                String request &#061; scanner.next();<br \/>\n            }<br \/>\n        }catch (IOException e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n    } <\/p>\n<p>\u4f7f\u7528Scanner\u7c7b\u8bfb\u53d6\u6570\u636e\u65f6&#xff0c;\u8bfb\u5230&#034;\u7a7a\u767d\u7b26&#034;(\u7a7a\u767d\u7b26\u662f\u4e00\u7c7b\u5b57\u7b26\u7684\u7edf\u79f0&#xff0c;\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\u6362\u884c&#xff0c;\u56de\u8f66&#xff0c;\u7a7a\u683c&#xff0c;\u5236\u8868\u7b26&#xff0c;\u7ffb\u9875\u7b26\u7b49)\u624d\u4f1a\u8bfb\u53d6\u5b8c\u6bd5 ,\u5ba2\u6237\u7aef\u5728\u53d1\u9001\u6570\u636e\u65f6&#xff0c;\u52a1\u5fc5\u5728\u6bcf\u4e2a\u8bf7\u6c42\u7684\u672b\u5c3e\u52a0\u4e0a\u7a7a\u767d\u7b26\u3002<\/p>\n<p>\u7531\u4e8eTCP\u662f\u6309\u7167\u5b57\u8282\u6765\u4f20\u8f93\u7684&#xff0c;\u5728\u5b9e\u9645\u4f20\u8f93\u4e2d&#xff0c;\u5e94\u8be5\u4f7f\u82e5\u5e72\u4e2a\u5b57\u8282\u6784\u6210\u4e00\u4e2a\u201c\u5e94\u7528\u5c42\u7684\u6570\u636e\u62a5\u201d&#xff0c;\u6b64\u65f6\u5c31\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u7a7a\u767d\u7b26\u4f5c\u4e3a\u201c\u5206\u5272\u7b26\u201d&#xff0c;\u6765\u533a\u5206\u4e0d\u540c\u7684\u6570\u636e\u62a5\u3002<\/p>\n<p>\u00a0\u5c06\u8bfb\u53d6\u7684\u8bf7\u6c42\u4ea4\u7ed9\u5904\u7406\u8bf7\u6c42\u7684\u51fd\u6570&#xff0c;\u4f7f\u7528\u7684\u662fprocess\u51fd\u6570&#xff0c;\u8fd9\u91cc\u5bf9\u8bf7\u6c42\u7684\u5904\u7406\u5b9e\u9645\u4e0a\u662f\u76f4\u63a5\u8fd4\u56de\u8bf7\u6c42&#xff08;\u56de\u663e\u670d\u52a1\u5668&#xff09;&#xff1a;<\/p>\n<p>String request &#061; scanner.next();<br \/>\nString response &#061; possessFun(request);<br \/>\noutputStream.write(response.getBytes()); <\/p>\n<p>\u5728\u8bfb\u53d6\u8bf7\u6c42\u4e4b\u524d&#xff0c;\u5e94\u8be5\u5224\u65ad\u6587\u4ef6\u662f\u5426\u6709\u8f93\u5165\u00a0&#xff0c;\u53ef\u4ee5\u5728\u8fdb\u5165while\u5faa\u73af\u4e4b\u540e\u4f7f\u7528if\u8bed\u53e5\u5224\u65ad\u8bf7\u6c42\u662f\u5426\u6709\u8f93\u5165&#xff0c;\u4f7f\u7528scanner\u7684next\u65b9\u6cd5\u6765\u5224\u65ad&#xff0c;\u8bf7\u6c42\u5230\u8fbe\u540e&#xff0c;\u5e76\u4e14\u5e26\u6709\u660e\u786e\u7684\u5206\u9694\u7b26\u5c31\u4f1a\u8fd4\u56detrue&#xff0c;\u5982\u679cTCP\u65ad\u5f00\u8fde\u63a5&#xff0c;\u5c31\u4f1a\u8fd4\u56defalse&#xff0c;\u4f7f\u7528scanner\u8bfb\u53d6\u5230\u6587\u4ef6\u672b\u5c3e\u6216\u8005TCP\u65ad\u5f00\u8fde\u63a5\u5c31\u4f1a\u8fd4\u56defalse&#xff0c;\u5426\u5219\u5c31\u4f1a\u963b\u585e\u7b49\u5f85\u5ba2\u6237\u7aef\u7ee7\u7eed\u53d1\u9001\u8bf7\u6c42&#xff1a;<\/p>\n<p>Tcp\u65ad\u5f00\u8fde\u63a5-&gt;\u963b\u585e\u89e3\u9664\u8fd4\u56defalse\u3002<\/p>\n<p>Tcp\u6ca1\u6709\u65ad\u5f00\u8fde\u63a5-&gt;\u5bf9\u65b9\u4eec\u6ca1\u6709\u53d1\u6570\u636e\u8fc7\u6765&#xff0c;\u963b\u585e\u7b49\u5f85\u3002<\/p>\n<p>\u5ba2\u6237\u7aef\u53d1\u9001\u8bf7\u6c42 -&gt; \u63a5\u89e6\u963b\u585e\u5e76\u8fd4\u56detrue\u3002<\/p>\n<p>\u670d\u52a1\u5668\u5b8c\u6574\u4ee3\u7801&#xff1a;<\/p>\n<p>import java.io.IOException;<br \/>\nimport java.io.InputStream;<br \/>\nimport java.io.OutputStream;<br \/>\nimport java.net.ServerSocket;<br \/>\nimport java.net.Socket;<br \/>\nimport java.util.Scanner;<\/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);<br \/>\n    }<br \/>\n    public void start() throws IOException {<br \/>\n        System.out.println(&#034;\u670d\u52a1\u5668\u542f\u52a8&#034;);<br \/>\n        while (true) {<br \/>\n            Socket socket &#061; serverSocket.accept();<br \/>\n            possess(socket);<br \/>\n        }<br \/>\n    }<br \/>\n    private void possess(Socket clientSocket)  {<br \/>\n        System.out.println(&#034;\u5ba2\u6237\u7aef\u4e0a\u7ebf&#034;);<br \/>\n        try(InputStream inputStream &#061; clientSocket.getInputStream();<br \/>\n            OutputStream outputStream &#061; clientSocket.getOutputStream()) {<br \/>\n            Scanner scanner &#061; new Scanner(inputStream);<br \/>\n            while (true) {<br \/>\n                if(!scanner.hasNext()) {<br \/>\n                    System.out.println(&#034;\u5ba2\u6237\u7aef\u4e0b\u7ebf&#034;);<br \/>\n                    break;<br \/>\n                }<br \/>\n                String request &#061; scanner.next();<br \/>\n                String response &#061; possessFun(request);<br \/>\n                outputStream.write(response.getBytes());<br \/>\n            }<br \/>\n        }catch (IOException e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n    }<br \/>\n    private String possessFun(String request) {<br \/>\n        return request&#043;&#034; \\\\n&#034;;<br \/>\n    }<br \/>\n} <\/p>\n<h3>\u5ba2\u6237\u7aef<\/h3>\n<p>\u00a0\u5ba2\u6237\u7aef\u5728\u6784\u9020\u65b9\u6cd5\u4e2d\u5e94\u8be5\u6709\u670d\u52a1\u5668\u7684ip\u5730\u5740\u548c\u7aef\u53e3\u53f7&#xff0c;\u5728\u6784\u9020\u8fc7\u7a0b\u4e2d\u5c31\u548c\u670d\u52a1\u5668\u5efa\u7acb\u8fde\u63a5\u3002<\/p>\n<p>    private Socket socket &#061; null;<br \/>\n    public TcpClientSocket(String address,int  port) throws IOException {<br \/>\n        socket &#061; new Socket(address,port);<br \/>\n    } <\/p>\n<p>\u5efa\u7acbstart\u65b9\u6cd5\u53bb\u542f\u52a8\u5ba2\u6237\u7aef\u8f93\u5165\u8bf7\u6c42&#xff0c;\u540c\u6837\u4f7f\u7528try-catch\u8bed\u53e5\u5b9e\u4f8b\u5316\u5b57\u8282\u6d41\u5bf9\u8c61&#xff0c;\u4f7f\u7528Scanner\u5728\u63a7\u5236\u53f0\u4e0a\u8f93\u5165\u8bf7\u6c42&#xff0c;\u5c06\u63a5\u6536\u7684\u8bed\u53e5\u53d1\u9001\u7ed9\u670d\u52a1\u5668\u4e4b\u524d\u4f7f\u7528<span style=\"color:#fe2c24\">\u2018\/n\u2019<\/span>\u4f5c\u4e3a\u5206\u5272\u7b26\u00a0&#xff0c;\u53d1\u9001\u7ed9\u670d\u52a1\u5668\u4f7f\u7528OutputStream&#xff0c;\u4f20\u8f93\u7684\u5355\u4f4d\u662f\u5b57\u8282&#xff0c;\u5c06\u8bf7\u6c42\u8f6c\u6362\u4e3abyte\u8fdb\u884c\u53d1\u9001\u3002<\/p>\n<p>    public void start() {<br \/>\n        System.out.println(&#034;&#039;\u5ba2\u6237\u7aef\u542f\u52a8&#034;);<br \/>\n        try(InputStream inputStream &#061; socket.getInputStream();<br \/>\n            OutputStream outputStream &#061; socket.getOutputStream()) {<br \/>\n            Scanner scanner &#061; new Scanner(System.in);<br \/>\n            Scanner Rescanner &#061; new Scanner(inputStream);<br \/>\n            while (true) {<br \/>\n                String request &#061; scanner.next();<br \/>\n                request &#043;&#061; &#034;\/n&#034;;<br \/>\n                outputStream.write(request.getBytes());<br \/>\n            }<br \/>\n        } <\/p>\n<p>\u7136\u540e\u5982\u540c\u670d\u52a1\u5668\u4e00\u6837&#xff0c;\u5224\u65ad\u6765\u81ea\u670d\u52a1\u5668\u7684\u54cd\u5e94\u662f\u5426\u5230\u8fbe&#xff0c;\u4f7f\u7528scanner\u63a5\u6536\u54cd\u5e94&#xff0c;\u5728\u5c06\u63a5\u6536\u7684\u54cd\u5e94\u6253\u5370\u5230\u63a7\u5236\u53f0&#xff0c;\u5ba2\u6237\u7aef\u5c31\u5b8c\u6210\u7f16\u5199&#xff1a;<\/p>\n<p>import java.io.IOException;<br \/>\nimport java.io.InputStream;<br \/>\nimport java.io.OutputStream;<br \/>\nimport java.net.Socket;<br \/>\nimport java.util.Scanner;<\/p>\n<p>public class TcpClientSocket {<br \/>\n    private Socket socket &#061; null;<br \/>\n    public TcpClientSocket(String address,int  port) throws IOException {<br \/>\n        socket &#061; new Socket(address,port);<br \/>\n    }<br \/>\n    public void start() {<br \/>\n        System.out.println(&#034;&#039;\u5ba2\u6237\u7aef\u542f\u52a8&#034;);<br \/>\n        try(InputStream inputStream &#061; socket.getInputStream();<br \/>\n            OutputStream outputStream &#061; socket.getOutputStream()) {<br \/>\n            Scanner scanner &#061; new Scanner(System.in);<br \/>\n            Scanner Rescanner &#061; new Scanner(inputStream);<br \/>\n            while (true) {<br \/>\n                String request &#061; scanner.next();<br \/>\n                request &#043;&#061; &#034;\/n&#034;;<br \/>\n                outputStream.write(request.getBytes());<br \/>\n                if(!Rescanner.hasNext()) {<br \/>\n                    break;<br \/>\n                }<br \/>\n                String response &#061; Rescanner.next();<br \/>\n                System.out.println(response);<br \/>\n            }<br \/>\n        }catch (IOException e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<p>\u00a0\u6b65\u9aa4&#xff1a;<\/p>\n<p><span style=\"background-color:#ffd900\">\u00a01.\u5ba2\u6237\u7aef\u4ece\u63a7\u5236\u53f0\u5f97\u5230\u8bf7\u6c42\u30022.\u5c06\u8bf7\u6c42\u53d1\u9001\u5230\u670d\u52a1\u56683.\u670d\u52a1\u5668\u63a5\u6536\u8bf7\u6c424.\u670d\u52a1\u5668\u5904\u7406\u8bf7\u6c425\u670d\u52a1\u5668.\u5c06\u54cd\u5e94\u53d1\u9001\u7ed9\u5ba2\u6237\u7aef6.\u5ba2\u6237\u7aef\u63a5\u6536\u54cd\u5e947.\u5c06\u54cd\u5e94\u8f93\u51fa\u5728\u63a7\u5236\u53f0\u3002<\/span><\/p>\n<h2 id=\"%E4%BC%98%E5%8C%96%E6%9C%8D%E5%8A%A1%E5%99%A8\">\u4f18\u5316\u670d\u52a1\u5668<\/h2>\n<h3 id=\"1.%E5%85%B3%E9%97%AD%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%88%9B%E5%BB%BA%E7%9A%84socket%E5%AF%B9%E8%B1%A1\">1.\u5173\u95ed\u670d\u52a1\u5668\u521b\u5efa\u7684socket\u5bf9\u8c61<\/h3>\n<p>serverrSocket\u4e0d\u9700\u8981\u7279\u522b\u5173\u95ed&#xff0c;\u56e0\u4e3a\u751f\u547d\u5468\u671f\u662f\u4f34\u968f\u6574\u4e2a\u670d\u52a1\u5668\u8fdb\u7a0b\u3002\u5ba2\u6237\u7aef\u7684socket\u4e5f\u662f\u5982\u6b64&#xff0c;\u4f46\u662f\u670d\u52a1\u5668\u7528\u4e8e\u63a5\u6536\u5ba2\u6237\u7aef\u4fe1\u606f\u7684socket\u5c31\u5fc5\u987b\u5173\u95ed&#xff0c;\u670d\u52a1\u5668\u4f1a\u5bf9\u5e94\u591a\u4e2a\u5ba2\u6237\u7aef&#xff0c;\u5982\u679c\u4f7f\u7528\u5b8c\u6bd5\u540e\u4e0d\u5173\u95ed\u5f53\u524d\u8d44\u6e90\u6587\u4ef6\u5f97\u4e0d\u5230\u91ca\u653e&#xff0c;\u5c31\u4f1a\u5f15\u8d77\u6587\u4ef6\u8d44\u6e90\u6cc4\u9732\u3002\u5728\u670d\u52a1\u5668\u4ee3\u7801\u4e2d\u52a0\u4e0afinally\u8bed\u53e5\u91ca\u653esocket\u5bf9\u8c61\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"900\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418161317-68027a1d61f1a.png\" width=\"1185\" \/><\/p>\n<h3 id=\"2.%E5%BC%95%E5%85%A5%E7%BA%BF%E7%A8%8B%E6%B1%A0%EF%BC%8C%E4%B8%BA%E5%A4%9A%E4%B8%AA%E5%AE%A2%E6%88%B7%E7%AB%AF%E6%8F%90%E4%BE%9B%E6%9C%8D%E5%8A%A1%C2%A0\">2.\u5f15\u5165\u7ebf\u7a0b\u6c60&#xff0c;\u4e3a\u591a\u4e2a\u5ba2\u6237\u7aef\u63d0\u4f9b\u670d\u52a1\u00a0<\/h3>\n<p>\u4e3b\u7ebf\u7a0b\u5904\u7406accept&#xff0c;\u6bcf\u6b21\u63a5\u6536\u4e00\u4e2aaccept\u5c31\u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\u6765\u670d\u52a1&#xff0c;\u8fd9\u91cc\u4f7f\u7528\u53ef\u6269\u5bb9\u7684\u7ebf\u7a0b\u6c60&#xff1a;<\/p>\n<p>    public void start() throws IOException {<br \/>\n        System.out.println(&#034;\u670d\u52a1\u5668\u542f\u52a8&#034;);<br \/>\n        \/\/\u81ea\u52a8\u6269\u5bb9\u7ebf\u7a0b\u6c60<br \/>\n        ExecutorService pool &#061; Executors.newCachedThreadPool();<br \/>\n        while (true) {<br \/>\n            Socket socket &#061; serverSocket.accept();<br \/>\n            pool.submit(new Runnable() {<br \/>\n                &#064;Override<br \/>\n                public void run() {<br \/>\n                    try {<br \/>\n                        possess(socket);<br \/>\n                    } catch (IOException e) {<br \/>\n                        throw new RuntimeException(e);<br \/>\n                    }<br \/>\n                }<br \/>\n            });<br \/>\n        }<br \/>\n    } <\/p>\n<p style=\"text-align:center\"><span style=\"background-color:#98c091\">\u6587\u7ae0\u5230\u8fd9\u91cc\u5c31\u7ed3\u675f\u4e86&#xff0c;\u611f\u8c22\u89c2\u770b\u3002<\/span><\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e15\u6b21\uff0c\u6536\u85cf17\u6b21\u3002\u7f51\u7edc\u7f16\u7a0b\uff0cTcp\uff0cUdp\u56de\u663e\u670d\u52a1\u5668\u7684\u5b9e\u73b0_\u56de\u663e\u670d\u52a1\u5668<\/p>\n","protected":false},"author":2,"featured_media":17725,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[78],"topic":[],"class_list":["post-17727","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-78"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u7f51\u7edc\u7f16\u7a0b\uff08UDP\\\\TCP\u56de\u663e\u670d\u52a1\u5668\uff09 - \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\/17727.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u7f51\u7edc\u7f16\u7a0b\uff08UDP\\\\TCP\u56de\u663e\u670d\u52a1\u5668\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e15\u6b21\uff0c\u6536\u85cf17\u6b21\u3002\u7f51\u7edc\u7f16\u7a0b\uff0cTcp\uff0cUdp\u56de\u663e\u670d\u52a1\u5668\u7684\u5b9e\u73b0_\u56de\u663e\u670d\u52a1\u5668\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/17727.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-18T16:13:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418161317-68027a1d02060.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=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/17727.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/17727.html\",\"name\":\"\u7f51\u7edc\u7f16\u7a0b\uff08UDP\\\\\\\\TCP\u56de\u663e\u670d\u52a1\u5668\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T16:13:18+00:00\",\"dateModified\":\"2025-04-18T16:13:18+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/17727.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/17727.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/17727.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u7f51\u7edc\u7f16\u7a0b\uff08UDP\\\\\\\\TCP\u56de\u663e\u670d\u52a1\u5668\uff09\"}]},{\"@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":"\u7f51\u7edc\u7f16\u7a0b\uff08UDP\\\\TCP\u56de\u663e\u670d\u52a1\u5668\uff09 - \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\/17727.html","og_locale":"zh_CN","og_type":"article","og_title":"\u7f51\u7edc\u7f16\u7a0b\uff08UDP\\\\TCP\u56de\u663e\u670d\u52a1\u5668\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e15\u6b21\uff0c\u6536\u85cf17\u6b21\u3002\u7f51\u7edc\u7f16\u7a0b\uff0cTcp\uff0cUdp\u56de\u663e\u670d\u52a1\u5668\u7684\u5b9e\u73b0_\u56de\u663e\u670d\u52a1\u5668","og_url":"https:\/\/www.wsisp.com\/helps\/17727.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T16:13:18+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418161317-68027a1d02060.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/17727.html","url":"https:\/\/www.wsisp.com\/helps\/17727.html","name":"\u7f51\u7edc\u7f16\u7a0b\uff08UDP\\\\TCP\u56de\u663e\u670d\u52a1\u5668\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T16:13:18+00:00","dateModified":"2025-04-18T16:13:18+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/17727.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/17727.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/17727.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u7f51\u7edc\u7f16\u7a0b\uff08UDP\\\\TCP\u56de\u663e\u670d\u52a1\u5668\uff09"}]},{"@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\/17727","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=17727"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/17727\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/17725"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=17727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=17727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=17727"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=17727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}