{"id":63470,"date":"2026-01-22T00:48:50","date_gmt":"2026-01-21T16:48:50","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/63470.html"},"modified":"2026-01-22T00:48:50","modified_gmt":"2026-01-21T16:48:50","slug":"java%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0%ef%bc%8c%e4%bb%8e%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b%e4%b8%89%e8%a6%81%e7%b4%a0%e5%88%b0tcp-udp%e5%8d%8f%e8%ae%ae","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/63470.html","title":{"rendered":"Java\u7f51\u7edc\u7f16\u7a0b\u5b66\u4e60\u7b14\u8bb0\uff0c\u4ece\u7f51\u7edc\u7f16\u7a0b\u4e09\u8981\u7d20\u5230TCP\/UDP\u534f\u8bae"},"content":{"rendered":"<h2>\u4ec0\u4e48\u662f\u7f51\u7edc\u7f16\u7a0b<\/h2>\n<p>\u4ec0\u4e48\u662f\u7f51\u7edc\u7f16\u7a0b&#xff0c;\u76f8\u6bd4\u4e8e\u7f16\u5199\u7a0b\u5e8f\u5728\u672c\u673a\u4e0a\u8fd0\u884c&#xff0c;\u7f51\u7edc\u7f16\u7a0b\u662f\u6307\u7f16\u5199\u4e24\u53f0\u4e0d\u540c\u7684\u8ba1\u7b97\u673a\u7684\u7a0b\u5e8f&#xff0c;\u57fa\u4e8e\u7f51\u7edc\u534f\u8bae&#xff0c;\u901a\u8fc7\u7f51\u7edc\u8fdb\u884c\u6570\u636e\u901a\u4fe1\u3002<\/p>\n<p>\u5e38\u89c1\u7684\u7f51\u7edc\u7a0b\u5e8f\u8f6f\u4ef6\u67b6\u6784\u6709&#xff1a;BS&#xff08;Broser\u6d4f\u89c8\u5668\/Server\u670d\u52a1\u5668&#xff09;\u67b6\u6784\u3001CS&#xff08;Client\u5ba2\u6237\u7aef\/Server\u670d\u52a1\u5668&#xff09;\u67b6\u6784<\/p>\n<li>BS\u67b6\u6784&#xff1a;\u4f18\u52bf\u662f\u7528\u6237\u4e0d\u7528\u4e0b\u8f7d\u5ba2\u6237\u7aef&#xff0c;\u4f7f\u7528\u6d4f\u89c8\u5668\u5373\u53ef\u5feb\u901f\u83b7\u53d6\u670d\u52a1&#xff0c;\u8fd0\u8425\u8005\u53ef\u968f\u65f6\u66f4\u65b0\u7a0b\u5e8f\u3002\u52a3\u52bf\u662f\u6240\u6709\u7a0b\u5e8f\u548c\u8d44\u6e90\u9700\u8981\u901a\u8fc7\u7f51\u7edc\u4f20\u8f93&#xff0c;\u4ea7\u54c1\u7cbe\u7f8e\u548c\u7ec6\u817b\u7a0b\u5ea6\u4e0d\u53caCS\u67b6\u6784\u7684\u4ea7\u54c1\u3002<\/li>\n<li>CS\u67b6\u6784&#xff1a;\u4f18\u7565\u52bf\u4e0eBS\u67b6\u6784\u76f8\u53cd\u3002\u4f18\u52bf\u662f\u7528\u6237\u63d0\u524d\u4e0b\u8f7d\u597d\u7a0b\u5e8f\u7684\u6240\u6709\u8d44\u6e90&#xff0c;\u4ea7\u54c1\u7684\u7cbe\u7f8e\u548c\u7ec6\u817b\u7a0b\u5e8f\u53ef\u4ee5\u505a\u5230\u975e\u5e38\u9ad8&#xff0c;\u800c\u4e14\u53ef\u4ee5\u66f4\u597d\u7684\u5229\u7528\u672c\u5730\u8ba1\u7b97\u673a\u7b97\u529b&#xff0c;\u6bd4\u59823A\u6e38\u620f\u90fd\u662fCS\u67b6\u6784\u3002\u52a3\u52bf\u662f\u9700\u8981\u7528\u6237\u4e0b\u8f7d\u5ba2\u6237\u7aef\u7a0b\u5e8f&#xff0c;\u7a0b\u5e8f\u66f4\u65b0\u65f6\u6bd4\u8f83\u9ebb\u70e6&#xff0c;\u9700\u8981\u5ba2\u6237\u7aef\u66f4\u65b0\u8f6f\u4ef6\u3002<\/li>\n<h2>\u7f51\u7edc\u7f16\u7a0b\u4e09\u8981\u7d20<\/h2>\n<p>\u8981\u5b9e\u73b0\u7f51\u7edc\u7f16\u7a0b&#xff0c;\u5fc5\u987b\u5b9e\u73b0\u7f51\u7edc\u901a\u4fe1\u9700\u8981\u786e\u5b9a\u901a\u4fe1\u5bf9\u8c61&#xff08;IP&#xff09;\u3001\u5bf9\u8c61\u4e2d\u7684\u5177\u4f53\u7a0b\u5e8f&#xff08;\u7aef\u53e3&#xff09;\u3001\u901a\u4fe1\u89c4\u5219&#xff08;\u534f\u8bae&#xff09;\u3002<\/p>\n<p>\u7b2c\u4e00\u6b65&#xff0c;\u9996\u5148\u8981\u5728\u7f51\u7edc\u4e2d&#xff0c;\u627e\u5230\u5bf9\u65b9\u7684\u8ba1\u7b97\u673a\u8bbe\u5907\u3002\u8ba1\u7b97\u673a\u7f51\u7edc\u4e2d&#xff0c;IP\u662f\u7f51\u7edc\u8bbe\u5907\u7684\u552f\u4e00\u5730\u5740\u3002 \u7b2c\u4e8c\u6b65&#xff0c;\u5728\u5bf9\u65b9\u7684\u8ba1\u7b97\u673a\u8bbe\u5907\u4e2d&#xff0c;\u627e\u5230\u8981\u901a\u4fe1\u7684\u8f6f\u4ef6&#xff0c;\u56e0\u4e3a\u8ba1\u7b97\u673a\u4e2d\u53ef\u80fd\u8fd0\u884c\u5f88\u591a\u7a0b\u5e8f\u3002\u6bd4\u5982\u5fae\u4fe1\u670d\u52a1\u7aef\u8981\u53d1\u9001\u6570\u636e\u5230\u7528\u6237\u624b\u673a&#xff0c;\u9700\u8981\u627e\u5230\u7528\u6237\u624b\u673a\u4e2d\u7684\u5fae\u4fe1\u5ba2\u6237\u7aef&#xff0c;\u800c\u7528\u6237\u624b\u673a\u4e2d\u53ef\u80fd\u6709\u5fae\u4fe1\u3001QQ\u3001\u6dd8\u5b9d\u7b49\u5f88\u591a\u5e94\u7528\u7a0b\u5e8f\u3002\u8ba1\u7b97\u673a\u7f51\u7edc\u4e2d&#xff0c;\u7aef\u53e3\u53f7\u662f\u533a\u5206\u7a0b\u5e8f\u8fdb\u7a0b\u7684\u7f16\u53f7\u3002 \u7b2c\u4e09\u6b65&#xff0c;\u9700\u8981\u786e\u5b9a\u901a\u4fe1\u65b9\u5f0f&#xff0c;\u5373\u7f51\u7edc\u534f\u8bae\u3002\u8ba1\u7b97\u673a\u7f51\u7edc\u534f\u8bae\u6709TCP\u3001UDP\u3001HTTP\u7b49\u534f\u8bae\u3002<\/p>\n<p>\u6240\u4ee5&#xff0c;\u7f51\u7edc\u7f16\u7a0b\u7684\u4e09\u8981\u7d20\u5c31\u662f&#xff1a;IP\u3001\u7aef\u53e3\u53f7\u3001\u7f51\u7edc\u534f\u8bae<\/p>\n<h3>IP<\/h3>\n<p>IP\u662f\u7f51\u7edc\u901a\u4fe1\u4e2d&#xff0c;\u8bbe\u5907\u7684\u5730\u5740&#xff0c;\u5177\u6709\u552f\u4e00\u6027\u3002<\/p>\n<p>IP\u6709IPV4\u548cIPV6\u4e24\u79cd\u3002<\/p>\n<h4>IPV4<\/h4>\n<p>IPV4\u662f\u6307IP\u4e92\u8054\u7f51\u901a\u4fe1\u534f\u8bae\u7b2c\u56db\u7248&#xff0c;IPV4\u75284\u4e2a\u5b57\u8282\u517132\u4f4d&#xff0c;\u75284\u7ec4&#xff08;\u6bcf\u7ec41\u4e2a\u5b57\u8282&#xff09;\u6765\u8868\u793a&#xff0c;\u6bd4\u5982&#xff1a;11000000 10101000 00000001 00000001\u3002IPV4\u91c7\u7528\u70b9\u5206\u5341\u8fdb\u5236&#xff0c;\u5373\u4f7f\u7528\u7b26\u53f7\u70b9.\u6765\u5206\u7ec4&#xff0c;\u91c7\u7528\u5341\u8fdb\u5236\u8868\u793a\u3002\u56e0\u6b64&#xff0c;\u4e0a\u8ff0IPV4\u5730\u5740\u8868\u793a\u4e3a&#xff1a;192.168.1.1<\/p>\n<p>IPV4\u517132\u4f4d&#xff0c;\u56e0\u6b64\u53ef\u4ee5\u533a\u5206\u7684\u5730\u5740\u67092\u768432\u6b21\u65b9\u5171\u8ba14,294,967,296&#xff0c;\u800c\u5168\u7403\u6709\u6570\u5341\u4ebf\u4eba&#xff0c;\u6bcf\u4e2a\u4eba\u53c8\u6709\u6570\u53f0\u53ef\u4e0a\u7f51\u7684\u8bbe\u5907\u3002\u56e0\u6b64&#xff0c;IPV4\u7684\u5730\u5740\u662f\u4e0d\u591f\u7528\u7684&#xff0c;\u5b9e\u9645\u4e0a&#xff0c;IPV4\u65e9\u57282019\u5e74\u5c31\u5df2\u7ecf\u7528\u5b8c\u4e86\u3002<\/p>\n<p>IPV4\u5df2\u7ecf\u7528\u5b8c\u4e86&#xff0c;\u800cIPV6\u5e76\u6ca1\u6709\u5927\u89c4\u6a21\u666e\u53ca&#xff0c;\u90a3IPV4\u662f\u5982\u4f55\u89e3\u51b3\u5f53\u524d\u8bbe\u5907IP\u5730\u5740\u4e0d\u591f\u7684\u95ee\u9898&#xff1f;\u7b54\u6848\u662f\u4f7f\u7528\u5c40\u57df\u7f51\u3002IPV4\u89c4\u5b9a192.168.0.0~192.168.255.255\u8fd9\u4e9b\u4e3a\u5c40\u57df\u7f51IP&#xff08;\u8fd8\u6709\u5176\u4ed6\u79c1\u6709IP\u6bb5&#xff0c;\u4e0d\u5c55\u5f00&#xff09;&#xff0c;\u4e00\u4e2a\u533a\u57df\u5185&#xff08;\u6bd4\u5982\u4e00\u4e2a\u7f51\u5427&#xff09;\u7684\u6240\u6709\u8bbe\u5907&#xff0c;\u4f7f\u7528\u4e00\u4e2a\u516c\u7f51IP&#xff0c;\u800c\u6240\u6709\u533a\u57df\u5185\u7684\u7f51\u7edc\u8bbe\u5907&#xff0c;\u4f7f\u7528\u5c40\u57df\u7f51IP\u3002\u5c40\u57df\u7f51\u5185\u7684\u6240\u6709\u8bbe\u5907\u4e0a\u7f51&#xff0c;\u90fd\u4f7f\u7528\u516c\u7f51IP\u5bf9\u5916\u4f20\u8f93\u548c\u63a5\u6536\u6570\u636e&#xff0c;\u7136\u540e\u901a\u8fc7NAT&#xff08;\u7f51\u7edc\u5730\u5740\u8f6c\u6362&#xff09;\u6280\u672f&#xff0c;\u5c06\u5c40\u57df\u7f51\u5404\u8bbe\u5907\u7684\u6570\u636e\u5305&#xff0c;\u518d\u5206\u53d1\u7ed9\u5404\u81ea\u8bbe\u5907\u3002<\/p>\n<p>\u516c\u7f51IP&#043;\u5c40\u57df\u7f51IP\u7684\u6280\u672f&#xff0c;\u9020\u6210\u4e86\u6211\u4eec\u76ee\u524d\u4f7f\u7528\u8bbe\u5907\u7684IPV4\u5730\u5740\u90fd\u662f192.168.X.X\u7684\u539f\u56e0\u3002<\/p>\n<p>\u5c40\u57df\u7f51IP\u5730\u5740&#xff0c;\u4e00\u822c\u662f\u8def\u7531\u5668\u901a\u8fc7DHCP\u6280\u672f\u968f\u673a\u5206\u914d\u7ed9\u7f51\u7edc\u8bbe\u5907\u7684&#xff0c;\u4e00\u6bb5\u65f6\u95f4\u540e\u5c40\u57df\u7f51IP\u5730\u5740\u4f1a\u6539\u7248\u3002\u9664\u6b64\u4e4b\u5916&#xff0c;\u6211\u4eec\u7684\u8bbe\u5907\u5728\u4e0d\u540c\u7684\u4e0a\u7f51\u73af\u5883&#xff0c;\u8def\u7531\u5668\u5206\u914d\u7684\u5c40\u57df\u7f51\u5730\u5740\u4e00\u822c\u90fd\u662f\u4e0d\u540c\u7684&#xff0c;\u6bd4\u5982\u5728\u6559\u5e08\u91cc\u8fdeWIFI&#xff0c;\u7b14\u8bb0\u672c\u7535\u8111\u88ab\u5206\u914d\u7684\u5c40\u57df\u7f51\u5730\u5740\u53ef\u80fd\u662f192.168.10.245&#xff0c;\u800c\u56de\u5230\u5bdd\u5ba4&#xff0c;\u8fde\u6709\u7ebf\u7f51&#xff0c;\u7b14\u8bb0\u672c\u7535\u8111\u88ab\u5206\u914d\u7684\u5c40\u57df\u7f51\u5730\u5740\u53d8\u6210\u4e86192.168.1.3\u3002\u56e0\u6b64&#xff0c;\u672c\u673a\u7a0b\u5e8f\u4e4b\u95f4\u8fdb\u884c\u901a\u4fe1&#xff0c;\u4e0d\u80fd\u4f7f\u7528\u5c40\u57df\u7f51IP\u5730\u5740&#xff0c;\u800c\u662f\u4f7f\u7528\u4e00\u4e2a\u88ab\u79f0\u4e3a\u672c\u673aIP\u6216\u8005\u56de\u73af\u5730\u5740\u7684\u7279\u6b8aIP&#xff1a;127.0.0.1\u3002\u7f51\u7edc\u8bbe\u5907\u5728\u8bc6\u522b\u5230\u56de\u73af\u5730\u5740\u4f5c\u4e3a\u76ee\u6807\u5730\u5740&#xff0c;\u4e0d\u4f1a\u5c06\u6570\u636e\u4f20\u8f93\u5230\u8def\u7531\u5668\u6216\u8005\u7f51\u5173&#xff0c;\u800c\u662f\u76f4\u63a5\u4f20\u7ed9\u672c\u673a\u3002<\/p>\n<h4>IPV6<\/h4>\n<p>\u4e3a\u89e3\u51b3IP\u67af\u7aed\u95ee\u9898&#xff0c;IPV6\u6a2a\u7a7a\u51fa\u4e16\u3002IPV6\u91c7\u752816\u4e2a\u5b57\u8282128\u4f4d&#xff0c;\u51718\u7ec4&#xff08;\u6bcf\u7ec4\u4e24\u4e2a\u5b57\u8282&#xff09;\u6765\u8868\u793a&#xff0c;\u6bd4\u5982&#xff1a;11111101 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000001\u3002IPV6\u91c7\u7528\u5192\u5206\u5341\u516d\u8fdb\u5236&#xff0c;\u5373\u4f7f\u7528\u7b26\u53f7\u5192\u53f7:\u6765\u5206\u7ec4&#xff0c;\u91c7\u7528\u5341\u516d\u8fdb\u5236\u6765\u8868\u793a\u3002\u56e0\u6b64&#xff0c;\u4e0a\u8ff0IPV6\u5730\u5740\u8868\u793a\u4e3a&#xff1a;fd00:0000:0000:0000:0000:0000:0000:0001\u3002\u7531\u4e8eIPV6\u5730\u5740\u5f88\u957f&#xff0c;\u56e0\u6b64\u56fa\u5b9a\u53ef\u4ee5\u7701\u7565\u6bcf\u4e00\u6700\u524d\u9762\u7684\u4e00\u8fde\u4e320&#xff0c;\u56e0\u6b64\u4e0a\u8ff0IPV6\u5730\u5740\u53ef\u7b80\u5199\u4e3a&#xff1a;fd00:0:0:0:0:0:0:1\u3002\u5e76\u4e14&#xff0c;\u89c4\u5b9a\u53ef\u4ee5\u8fdb\u4e00\u6b65\u5c06\u4e2d\u95f4\u76840\u7701\u7565&#xff0c;\u5373\u538b\u7f29\u8868\u793a\u4e3a&#xff1a;fd00::1<\/p>\n<p>IPV6\u5171128\u4f4d&#xff0c;\u56e0\u6b64\u53ef\u4ee5\u533a\u5206\u7684\u5730\u5740\u4e3a2\u7684128\u6b21\u65b9\u4e2a&#xff0c;\u53ef\u4ee5\u4e3a\u5730\u7403\u4e0a\u6bcf\u4e00\u7c92\u6c99\u5b50\u90fd\u5206\u914d\u4e00\u4e2a\u552f\u4e00\u7684IP\u5730\u5740\u3002\u56e0\u6b64&#xff0c;IPV6\u4e00\u5b9a\u662f\u8db3\u591f\u4eba\u4eec\u4f7f\u7528\u3002\u76ee\u524d&#xff0c;IPV6\u6b63\u5728\u9010\u6b65\u63a8\u5e7f&#xff0c;\u5168\u9762\u53d6\u4ee3IPV4\u4ecd\u9700\u65f6\u95f4&#xff0c;\u76ee\u524d\u5f88\u591a\u73af\u5883\u662f\u53cc\u6808&#xff08;IPV4&#043;IPV6&#xff09;\u8fd0\u884c\u3002<\/p>\n<h3>\u7aef\u53e3<\/h3>\n<p>\u7aef\u53e3\u662f\u8ba1\u7b97\u673a\u4e2d\u5e94\u7528\u7a0b\u5e8f\u5411\u5916\u53d1\u9001\u6570\u636e\/\u63a5\u6536\u6570\u636e\u7684\u201c\u53e3\u201d&#xff0c;\u6bcf\u4e2a\u5e94\u7528\u7a0b\u5e8f\u90fd\u6709\u4e00\u4e2a\u7aef\u53e3\u53f7\u3002<\/p>\n<p>\u7aef\u53e3\u53f7\u662f\u7528\u4e24\u4e2a\u5b57\u8282\u6765\u8868\u793a\u7684&#xff0c;\u4e5f\u5c31\u662f\u4e00\u5171\u67090~65535&#xff0c;\u4e00\u517165536\u4e2a\u7aef\u53e3\u53f7\u3002<\/p>\n<p>\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u65f6&#xff0c;\u64cd\u4f5c\u7cfb\u7edf\u4f1a\u4e3a\u5e94\u7528\u7a0b\u5e8f\u5206\u914d\u4e00\u4e2a\u7aef\u53e3\u53f7&#xff0c;\u5e94\u7528\u7a0b\u5e8f\u5c31\u7528\u8fd9\u4e2a\u7aef\u53e3\u53f7\u5411\u7f51\u7edc\u6536\u53d1\u6570\u636e\u3002<\/p>\n<h3>\u534f\u8bae<\/h3>\n<p>\u7f51\u7edc\u534f\u8bae\u662f\u6307\u7f51\u7edc\u901a\u4fe1\u3001\u6570\u636e\u4f20\u8f93\u7684\u6807\u51c6\u6216\u89c4\u8303\u3002\u8ba1\u7b97\u673a\u7f51\u7edc\u4e2d\u6709OSI\u4e03\u5c42\u6a21\u578b\u548cTCP\/IP\u6a21\u578b&#xff0c;\u5176\u4e2dTCP\/IP\u6a21\u578b\u5c06\u7f51\u7edc\u5212\u5206\u4e3a\u5e94\u7528\u5c42\u3001\u4f20\u8f93\u5c42\u3001\u7f51\u7edc\u5c42\u548c\u7269\u7406\u94fe\u8def\u5c42&#xff0c;TCP\/IP\u6a21\u578b\u662f\u884c\u4e1a\u9ed8\u8ba4\u7684\u6807\u51c6\u3002<\/p>\n<p>TCP\/IP\u6a21\u578b\u4e2d\u4e0d\u540c\u5c42\u6709\u4e0d\u540c\u7684\u7f51\u7edc\u534f\u8bae&#xff0c;\u6bd4\u5982HTTP\u3001FTP\u7b49\u5c31\u662f\u5e94\u7528\u5c42\u7684\u534f\u8bae&#xff0c;\u800cTCP\u3001UDP\u662f\u4f20\u8f93\u5c42\u7684\u534f\u8bae&#xff0c;IP\u662f\u7f51\u7edc\u5c42\u7684\u534f\u8bae\u3002<\/p>\n<h2>UDP \u7a0b\u5e8f\u901a\u4fe1<\/h2>\n<p>UDP\u534f\u8bae\u7279\u70b9\u662f\u65e0\u8fde\u63a5&#xff0c;\u53d1\u9001\u540e\u4e0d\u7ba1&#xff0c;\u6240\u4ee5\u901f\u5ea6\u5feb\u3002<\/p>\n<p>\u521b\u5efaUDP\u53d1\u9001\u6570\u636e\u7684\u7a0b\u5e8f\u6b65\u9aa4&#xff1a;<\/p>\n<li>\u521b\u5efa\u4e00\u4e2a\u53d1\u9001\u6570\u636e\u7684\u901a\u4fe1\u7aef\u70b9&#xff0c;\u9700\u5305\u62ec\u7f51\u7edc\u7f16\u7a0b\u4e09\u8981\u7d20&#xff1a;IP\u3001\u7aef\u53e3\u548c\u534f\u8bae\u3002\u53d1\u9001\u65f6\u7684IP\u662f\u672c\u673aIP&#xff0c;\u65e0\u6cd5\u81ea\u5b9a\u4e49&#xff08;\u66f4\u51c6\u786e\u7684\u662f&#xff1a;\u5728\u521b\u5efaDatagramSocket\u65f6&#xff0c;\u53ef\u4ee5\u7528\u5e26IP\u5bf9\u8c61\u7684\u6784\u9020\u51fd\u6570\u7ed1\u5b9a\u5230\u6307\u5b9a\u7684\u672c\u5730IP\u5730\u5740\u548c\u7aef\u53e3&#xff0c;\u4f46\u662f\u4e00\u822c\u4e0d\u7528IP\u5bf9\u8c61\u4f5c\u4e3a\u6784\u9020\u51fd\u6570\u53c2\u6570&#xff0c;\u9ed8\u8ba4\u4e3a\u672c\u673aIP&#xff09;\u3002\u7aef\u53e3\u53f7\u53ef\u6307\u5b9a\u53d1\u9001\u7aef\u53e3\u53f7&#xff0c;\u4f46\u662f\u7531\u4e8e\u7aef\u53e3\u53f7\u4e0d\u80fd\u4e0e\u522b\u7684\u7a0b\u5e8f\u5360\u7528\u7684\u7aef\u53e3\u53f7&#xff0c;\u56e0\u6b64\u4e00\u822c\u4f7f\u7528\u7cfb\u7edf\u7ed9\u7684\u7aef\u53e3\u53f7\u3002\u534f\u8bae\u5219\u4f53\u73b0\u5230\u7c7b\u4e0a&#xff0c;UDP\u4f7f\u7528DatagramSocket\u3002<\/li>\n<li>\u5c01\u88c5\u6570\u636e\u5305\u3002\u5c31\u50cf\u5c01\u88c5\u53d1\u9001\u51fa\u53bb\u7684\u5feb\u9012\u5305\u9700\u8981\u5305\u542b\u6536\u8d27\u5730\u5740\u548c\u6536\u8d27\u4eba\u3002UDP\u6570\u636e\u5305\u9700\u8981\u5305\u542b\u53d1\u9001\u7684\u6570\u636e\u672c\u8eab&#xff08;\u5b57\u8282\u6570\u7ec4&#xff09;\u3001\u76ee\u6807\u5730\u5740&#xff08;IP&#xff09;&#xff0c;\u76ee\u6807\u7aef\u53e3\u53f7\u3002\u5176\u4e2d&#xff0c;IP\u9700\u8981\u4f7f\u7528IP\u7c7bInetAddress\u521b\u5efa\u5bf9\u8c61\u3002UDP\u6570\u636e\u5305\u4e3aDatagramPacket\u7c7b&#xff0c;\u9700\u8981\u7528\u5b57\u8282\u6570\u7ec4\u6570\u636e\u672c\u8eab\u3001IP\u5bf9\u8c61\u548c\u7aef\u53e3\u53f7\u5c01\u88c5\u3002<\/li>\n<li>\u53d1\u9001\u6570\u636e\u3002DatagramSocket\u5bf9\u8c61\u8c03\u7528\u65b9\u6cd5\u53d1\u9001\u6570\u636e\u5305\u3002<\/li>\n<li>\u91ca\u653e\u8d44\u6e90\u3002DatagramSocket\u5bf9\u8c61\u5b58\u5728\u65f6\u5360\u7528\u4e86\u7cfb\u7edf\u8d44\u6e90&#xff0c;\u56e0\u4e3a\u7cfb\u7edf\u5f00\u8f9f\u4e86\u7aef\u53e3\u53f7\u8ba9\u7a0b\u5e8f\u72ec\u5360\u4f7f\u7528&#xff0c;\u56e0\u6b64\u9700\u8981\u8c03\u7528close&#xff08;&#xff09;\u65b9\u6cd5\u91ca\u653e\u8d44\u6e90\u3002<\/li>\n<p><span class=\"token comment\">\/\/ \u53d1\u9001\u7aef  <\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">SendMessage<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> args<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">throws<\/span> <span class=\"token class-name\">IOException<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ 1. \u521b\u5efa\u4e00\u4e2a\u53d1\u9001UDP\u7684\u901a\u4fe1\u5bf9\u8c61  <\/span><br \/>\n        <span class=\"token class-name\">DatagramSocket<\/span> socket <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">DatagramSocket<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <\/p>\n<p>        <span class=\"token comment\">\/\/ 2. \u5c01\u88c5\u6570\u636e\u5305  <\/span><br \/>\n        <span class=\"token comment\">\/\/ \u76ee\u7684\u5730\u5740\u548c\u7aef\u53e3  <\/span><br \/>\n        <span class=\"token class-name\">String<\/span> ip <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;127.0.0.1&#034;<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u53d1\u9001\u5230\u672c\u673a&#xff0c;\u7528\u56de\u73af\u5730\u5740  <\/span><br \/>\n        <span class=\"token class-name\">InetAddress<\/span> destinationIP <span class=\"token operator\">&#061;<\/span> <span class=\"token class-name\">InetAddress<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">getByName<\/span><span class=\"token punctuation\">(<\/span>ip<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u76ee\u7684\u5730\u5740  <\/span><br \/>\n        <span class=\"token keyword\">int<\/span> destinationPort <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">10086<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u5f85\u53d1\u9001\u7684\u6570\u636e  <\/span><br \/>\n        <span class=\"token class-name\">String<\/span> data <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;hello, world&#034;<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u5f85\u53d1\u9001\u7684\u6570\u636e&#xff1a;hello, world  <\/span><br \/>\n        <span class=\"token keyword\">byte<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> dataBytes <span class=\"token operator\">&#061;<\/span> data<span class=\"token punctuation\">.<\/span><span class=\"token function\">getBytes<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u8f6c\u6362\u4e3a\u5b57\u8282\u6570\u7ec4  <\/span><br \/>\n        <span class=\"token class-name\">DatagramPacket<\/span> packet <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">DatagramPacket<\/span><span class=\"token punctuation\">(<\/span>dataBytes<span class=\"token punctuation\">,<\/span> dataBytes<span class=\"token punctuation\">.<\/span>length<span class=\"token punctuation\">,<\/span> destinationIP<span class=\"token punctuation\">,<\/span> destinationPort<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u6570\u636e\u5305\u5bf9\u8c61  <\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ 3. \u53d1\u9001\u6570\u636e\u5305  <\/span><br \/>\n        socket<span class=\"token punctuation\">.<\/span><span class=\"token function\">send<\/span><span class=\"token punctuation\">(<\/span>packet<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <\/p>\n<p>        <span class=\"token comment\">\/\/ 4. \u91ca\u653e\u8d44\u6e90  <\/span><br \/>\n        socket<span class=\"token punctuation\">.<\/span><span class=\"token function\">close<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>UDP\u63a5\u6536\u6570\u636e\u7684\u7a0b\u5e8f\u6b65\u9aa4&#xff1a;<\/p>\n<li>\u540c\u53d1\u9001\u6570\u636e\u76f8\u4f3c&#xff0c;\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u63a5\u6536\u6570\u636e\u7684\u901a\u4fe1\u7aef\u70b9&#xff0c;\u4e5f\u662f\u5305\u62ec\u7f51\u7edc\u7f16\u7a0b\u4e09\u8981\u7d20&#xff1a;IP\u3001\u7aef\u53e3\u548c\u534f\u8bae\u3002\u63a5\u6536\u65f6\u7684IP\u662f\u672c\u673a\u53f7\u3002\u7aef\u53e3\u53f7\u9700\u8981\u6ce8\u610f&#xff0c;\u8981\u4f7f\u7528\u4e0e\u53d1\u9001\u6570\u636e\u4e2d\u7684\u53d1\u9001\u6570\u636e\u5305\u7684\u76ee\u6807\u7aef\u53e3\u53f7&#xff0c;\u4e0d\u5bf9\u5e94\u5219\u63a5\u6536\u4e0d\u5230\u6570\u636e\u3002\u534f\u8bae\u4e5f\u662f\u4f53\u73b0\u5230\u7c7b\u4e0a&#xff0c;UDP\u4e3aDatagramSocket\u3002<\/li>\n<li>\u63a5\u6536\u6570\u636e\u3002\u53d1\u9001\u6570\u636e\u7684\u662fDatagramPacket\u5bf9\u8c61&#xff0c;\u63a5\u6536\u6570\u636e\u4e5f\u9700\u8981\u7528\u4e00\u4e2aDatagramPacket\u5bf9\u8c61\u8fdb\u884c\u63a5\u6536&#xff0c;\u53ef\u4ee5\u60f3\u8c61\u4e3a\u6536\u5feb\u9012\u65f6&#xff0c;\u9700\u8981\u7528\u4e00\u4e2a\u5feb\u9012\u76d2\u5b50\u53bb\u63a5\u6536\u3002\u4e0e\u53d1\u9001\u65f6\u9700\u8981\u6570\u636e\u5305DatagramPacket\u5bf9\u8c61\u9700\u8981\u5305\u542b\u6570\u636e\u672c\u8eab&#xff08;\u5b57\u8282\u6570\u7ec4&#xff09;\u3001\u76ee\u6807\u5730\u5740&#xff08;IP&#xff09;&#xff0c;\u76ee\u6807\u7aef\u53e3\u53f7\u7b49\u5185\u5bb9\u65f6\u4e0d\u540c&#xff0c;\u63a5\u6536\u6570\u636e\u7684\u6570\u636e\u5305&#xff0c;\u53ea\u9700\u8981\u5b9a\u4e49\u6570\u636e\u5305\u7684\u5927\u5c0f\u5373\u53ef&#xff08;\u5b57\u8282\u6570\u7ec4\u548c\u63a5\u6536\u6570\u636e\u7684\u957f\u5ea6&#xff09;\u3002<\/li>\n<li>\u89e3\u6790\u6570\u636e\u3002\u63a5\u6536\u7684\u662fDatagramPacket\u5bf9\u8c61&#xff0c;\u8c03\u7528\u76f8\u5e94\u7684\u65b9\u6cd5&#xff0c;\u53ef\u4ee5\u83b7\u53d6\u6570\u636e\u5305\u7684\u6570\u636e\u672c\u8eab\u3001\u6765\u6e90\u5730\u5740&#xff08;IP&#xff09;\u3001\u6765\u6e90\u7aef\u53e3\u53f7\u3002<\/li>\n<li>\u5173\u95ed\u8d44\u6e90\u3002\u4e0e\u53d1\u9001\u6570\u636e\u76f8\u540c&#xff0c;\u9700\u8981\u8c03\u7528close&#xff08;&#xff09;\u65b9\u6cd5\u91ca\u653e\u8d44\u6e90\u3002<\/li>\n<p><span class=\"token comment\">\/\/ \u63a5\u6536\u7aef  <\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">ReceiveMessage<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> args<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">throws<\/span> <span class=\"token class-name\">IOException<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ 1. \u521b\u5efa\u4e00\u4e2a\u63a5\u6536UDP\u7684\u901a\u4fe1\u5bf9\u8c61  <\/span><br \/>\n        <span class=\"token class-name\">DatagramSocket<\/span> socket <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">DatagramSocket<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">10086<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u6307\u5b9a\u63a5\u6536\u7aef\u53e3\u4e3a10086  <\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ 2. \u63a5\u6536\u6570\u636e  <\/span><br \/>\n        <span class=\"token keyword\">byte<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> buffer <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token keyword\">byte<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">1024<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u521b\u5efa\u4e00\u4e2a1024\u5b57\u8282\u7684\u5b57\u8282\u6570\u7ec4\u4f5c\u4e3a\u6570\u636e\u7f13\u51b2\u533a&#xff0c;\u7528\u4e8e\u4e34\u65f6\u5b58\u50a8\u4ece\u7f51\u7edc\u63a5\u6536\u5230\u7684\u6570\u636e  <\/span><br \/>\n        <span class=\"token class-name\">DatagramPacket<\/span> packet <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">DatagramPacket<\/span><span class=\"token punctuation\">(<\/span>buffer<span class=\"token punctuation\">,<\/span> buffer<span class=\"token punctuation\">.<\/span>length<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5305\u5bf9\u8c61&#xff0c;\u6700\u5927\u63a5\u6536\u6570\u636e\u957f\u5ea6\u4e3a\u6570\u7ec4\u957f\u5ea6  <\/span><br \/>\n        socket<span class=\"token punctuation\">.<\/span><span class=\"token function\">receive<\/span><span class=\"token punctuation\">(<\/span>packet<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <\/p>\n<p>        <span class=\"token comment\">\/\/ 3. \u89e3\u6790\u6570\u636e  <\/span><br \/>\n        <span class=\"token keyword\">byte<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> data <span class=\"token operator\">&#061;<\/span> packet<span class=\"token punctuation\">.<\/span><span class=\"token function\">getData<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u83b7\u53d6\u6570\u636e\u5305\u4e2d\u7684\u6570\u636e  <\/span><br \/>\n        <span class=\"token class-name\">String<\/span> receivedData <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">String<\/span><span class=\"token punctuation\">(<\/span>data<span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> packet<span class=\"token punctuation\">.<\/span><span class=\"token function\">getLength<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u5c06\u6570\u636e\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32  <\/span><br \/>\n        <span class=\"token class-name\">InetAddress<\/span> sourceAddress <span class=\"token operator\">&#061;<\/span> packet<span class=\"token punctuation\">.<\/span><span class=\"token function\">getAddress<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u83b7\u53d6\u53d1\u9001\u65b9\u7684IP\u5730\u5740  <\/span><br \/>\n        <span class=\"token class-name\">String<\/span> sourceAddressStr <span class=\"token operator\">&#061;<\/span> sourceAddress<span class=\"token punctuation\">.<\/span><span class=\"token function\">getHostAddress<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u89e3\u6790\u4e3aIP\u5730\u5740\u5b57\u7b26\u4e32  <\/span><br \/>\n        <span class=\"token keyword\">int<\/span> sourcePort <span class=\"token operator\">&#061;<\/span> packet<span class=\"token punctuation\">.<\/span><span class=\"token function\">getPort<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u83b7\u53d6\u53d1\u9001\u65b9\u7684\u7aef\u53e3\u53f7  <\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ \u6253\u5370\u51fa\u63a5\u6536\u5230\u7684\u6570\u636e\u548c\u53d1\u9001\u65b9\u7684IP\u5730\u5740\u53ca\u7aef\u53e3\u53f7  <\/span><br \/>\n        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u6536\u5230\u6765\u81eaIP\u4e3a&#034;<\/span> <span class=\"token operator\">&#043;<\/span> sourceAddressStr <span class=\"token operator\">&#043;<\/span> <span class=\"token string\">&#034;&#xff0c;\u7aef\u53e3\u53f7\u4e3a&#034;<\/span> <span class=\"token operator\">&#043;<\/span> sourcePort <span class=\"token operator\">&#043;<\/span> <span class=\"token string\">&#034;\u7684\u6570\u636e&#xff1a;&#034;<\/span> <span class=\"token operator\">&#043;<\/span> receivedData<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <\/p>\n<p>        <span class=\"token comment\">\/\/ 4. \u91ca\u653e\u8d44\u6e90  <\/span><br \/>\n        socket<span class=\"token punctuation\">.<\/span><span class=\"token function\">close<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u6536\u5230\u6765\u81eaIP\u4e3a127.0.0.1&#xff0c;\u7aef\u53e3\u53f7\u4e3a65290\u7684\u6570\u636e&#xff1a;hello, world<\/p>\n<p>\u8fdb\u7a0b\u5df2\u7ed3\u675f&#xff0c;\u9000\u51fa\u4ee3\u7801\u4e3a <span class=\"token number\">0<\/span><\/p>\n<h2>TCP \u7a0b\u5e8f\u901a\u4fe1<\/h2>\n<p>TCP\u534f\u8bae\u662f\u5efa\u7acb\u8fde\u63a5\u7684\u534f\u8bae&#xff0c;\u4e5f\u5c31\u662f\u5728\u53d1\u9001\u6570\u636e\u4e4b\u524d&#xff0c;\u9700\u8981\u5148\u5efa\u7acb\u8fde\u63a5&#xff0c;\u8fde\u63a5\u5efa\u7acb\u5931\u8d25\u5219\u4f1a\u5f02\u5e38&#xff0c;\u4e0d\u53ef\u53d1\u9001\u6570\u636e\u3002TCP\u534f\u8bae\u4e0eUDP\u534f\u8bae\u4e0d\u540c&#xff0c;TCP\u53d1\u9001\u6570\u636e\u65e0\u9700\u5c01\u88c5\u6210\u6570\u636e\u5305&#xff0c;\u8fd8\u662f\u901a\u8fc7\u6570\u636e\u6d41\u53d1\u9001\u6570\u636e&#xff0c;\u56e0\u6b64\u53d1\u9001\u548c\u63a5\u6536\u6570\u636e\u5982\u540cIO\u6d41\u3002<\/p>\n<p>TCP\u534f\u8bae\u9700\u8981\u901a\u8fc7\u4e09\u6b21\u63e1\u624b\u5efa\u7acb\u8fde\u63a5&#xff1a;<\/p>\n<li>\u7b2c\u4e00\u6b21\u63e1\u624b&#xff1a;\u5ba2\u6237\u7aef\u5f80\u670d\u52a1\u7aef\u53d1\u9001\u4fe1\u606f&#xff0c;\u8bf7\u6c42\u5efa\u7acb\u8fde\u63a5<\/li>\n<li>\u7b2c\u4e8c\u6b21\u63e1\u624b&#xff1a;\u670d\u52a1\u7aef\u53d1\u9001\u4fe1\u606f&#xff0c;\u8868\u660e\u7edf\u4e00\u5efa\u7acb\u8fde\u63a5\u3002\u6b64\u65f6&#xff0c;\u670d\u52a1\u7aef\u5df2\u5c31\u7eea&#xff0c;\u7b49\u5f85\u5ba2\u6237\u7aef\u786e\u8ba4\u5c31\u7eea<\/li>\n<li>\u7b2c\u4e09\u6b21\u63e1\u624b&#xff1a;\u5ba2\u6237\u7aef\u5f80\u670d\u52a1\u7aef\u53d1\u9001\u6d88\u606f&#xff0c;\u8868\u660e\u81ea\u5df1\u5df2\u5c31\u7eea&#xff0c;\u51c6\u5907\u53d1\u9001\u6570\u636e\u3002\u670d\u52a1\u7aef\u6536\u5230\u6d88\u606f&#xff0c;\u786e\u8ba4\u5ba2\u6237\u7aef\u5c31\u7eea&#xff0c;\u7b49\u5f85\u6536\u53d6\u6d88\u606f\u3002<\/li>\n<p>\u521b\u5efaTCP\u53d1\u9001\u6d88\u606f\u7684\u7a0b\u5e8f\u6b65\u9aa4\u4e3a&#xff1a;<\/p>\n<li>\u521b\u5efa\u4e00\u4e2a\u5ba2\u6237\u7aef\u7684\u901a\u4fe1\u7aef\u70b9&#xff0c;\u4e0eUDP\u7684DatagramSocket\u4e0d\u9700\u8981\u63a5\u6536\u7aefIP\u548c\u7aef\u53e3\u53f7\u4f5c\u4e3a\u53c2\u6570\u4e0d\u540c&#xff08;\u56e0\u4e3a\u63a5\u6536\u7aefIP\u548c\u7aef\u53e3\u53f7\u88ab\u5c01\u88c5\u5230\u4e86\u6570\u636e\u5305DatagramPacket\u5185&#xff09;&#xff0c;\u5ba2\u6237\u7aefSocket\u5bf9\u8c61\u5728\u521b\u5efa\u65f6\u5c31\u9700\u8981\u63a5\u6536\u7aefIP\u548c\u7aef\u53e3\u53f7&#xff0c;\u56e0\u4e3a\u5728\u53d1\u9001\u6570\u636e\u4e4b\u524d&#xff0c;\u5c31\u8981\u4e0e\u670d\u52a1\u7aef\u5efa\u7acb\u8fde\u63a5&#xff08;\u521b\u5efa\u5bf9\u8c61\u65f6\u5c31\u5efa\u7acb\u8fde\u63a5&#xff09;\u3002\u5ba2\u6237\u7aefSocket\u5bf9\u8c61\u521b\u5efa\u4e0eDatagramSocket\u76f8\u4f3c\u70b9\u5728\u4e8e&#xff0c;\u53ef\u4ee5\u4e0d\u6307\u5b9a\u672c\u673a\u7684IP\u548c\u7aef\u53e3\u53f7&#xff0c;\u4f7f\u7528\u7cfb\u7edf\u7ed9\u7684\u7aef\u53e3\u53f7\u548c\u672c\u673aIP\u3002<\/li>\n<li>\u4eceSocket\u4e2d\u83b7\u53d6\u53d1\u9001\u6570\u636e\u7684\u8f93\u51fa\u6d41&#xff08;\u539f\u59cb\u5b57\u8282\u6d41\u51fa\u7559&#xff09;&#xff0c;\u901a\u8fc7\u8f93\u51fa\u6d41\u53d1\u9001\u6570\u636e\u3002Socket\u8f93\u51fa\u6d41\u662fIO\u6d41&#xff0c;\u56e0\u6b64\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5b57\u8282\u6d41\u3001\u5b57\u7b26\u6d41\u3001\u8f6c\u6362\u6d41\u3001\u7f13\u51b2\u6d41\u7b49\u539f\u59cb\u6d41\u548c\u5904\u7406\u6d41\u3002<\/li>\n<li>\u91ca\u653e\u8d44\u6e90\u3002\u521b\u5efaSocket\u5360\u7528\u7cfb\u7edf\u8d44\u6e90&#xff0c;\u56e0\u4e3a\u7cfb\u7edf\u5206\u914d\u4e86\u7aef\u53e3\u53f7&#xff0c;\u9700\u8981\u8c03\u7528close()\u65b9\u6cd5\u91ca\u653e\u8d44\u6e90\u3002\u6b64\u5916&#xff0c;IO\u6d41\u4e5f\u9700\u8981\u5173\u95ed\u3002\u9700\u8981\u6ce8\u610f&#xff0c;\u91ca\u653e\u8d44\u6e90\u6709\u4e00\u5b9a\u987a\u5e8f&#xff0c;\u5ba2\u6237\u7aef\u53d1\u9001\u5b8c\u6570\u636e\u7acb\u9a6c\u8fdb\u884c\u5173\u95ed&#xff0c;\u5b58\u5728\u4e24\u79cd\u53ef\u80fd&#xff1a;1. \u6570\u636e\u8fd8\u5728\u7f13\u51b2\u533a\u672a\u88ab\u5b8c\u5168\u53d1\u9001&#xff1b;2. \u670d\u52a1\u7aef\u672a\u5b8c\u5168\u63a5\u6536\u6570\u636e\u3002\u56e0\u6b64&#xff0c;\u4f7f\u7528flush()\u8ba9\u7f13\u51b2\u533a\u7684\u6570\u636e\u7acb\u5373\u53d1\u9001\u3002<\/li>\n<p><span class=\"token comment\">\/\/ \u5ba2\u6237\u7aef  <\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Client<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> args<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">throws<\/span> <span class=\"token class-name\">IOException<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ 1. \u521b\u5efa\u4e00\u4e2aSocket\u5bf9\u8c61  <\/span><br \/>\n        <span class=\"token class-name\">Socket<\/span> socket <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Socket<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;127.0.0.1&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">52522<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u6307\u5b9a\u63a5\u6536\u7aef\u7684IP\u548c\u7aef\u53e3  <\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ 2. \u901a\u8fc7Socket\u5bf9\u8c61\u83b7\u53d6\u8f93\u51fa\u6d41  <\/span><br \/>\n        <span class=\"token class-name\">OutputStream<\/span> os <span class=\"token operator\">&#061;<\/span> socket<span class=\"token punctuation\">.<\/span><span class=\"token function\">getOutputStream<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">BufferedOutputStream<\/span> bos <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">BufferedOutputStream<\/span><span class=\"token punctuation\">(<\/span>os<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u4f7f\u7528\u7f13\u51b2\u6d41&#xff08;\u4ec5\u505a\u6f14\u793a&#xff0c;\u975e\u5fc5\u987b&#xff09;  <\/span><br \/>\n        <span class=\"token class-name\">OutputStreamWriter<\/span> osw <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">OutputStreamWriter<\/span><span class=\"token punctuation\">(<\/span>bos<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u4f7f\u7528OutputStreamWriter\u5c06\u5b57\u8282\u6d41\u8f6c\u6362\u4e3a\u5b57\u7b26\u6d41  <\/span><br \/>\n        osw<span class=\"token punctuation\">.<\/span><span class=\"token function\">write<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Hello, Server!&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u5199\u5165\u6570\u636e  <\/span><br \/>\n        osw<span class=\"token punctuation\">.<\/span><span class=\"token function\">flush<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u5237\u65b0\u7f13\u51b2\u533a&#xff0c;\u786e\u4fdd\u6570\u636e\u53d1\u9001  <\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ 3. \u91ca\u653e\u8d44\u6e90&#xff08;\u6309\u6b63\u786e\u987a\u5e8f&#xff09;  <\/span><br \/>\n        osw<span class=\"token punctuation\">.<\/span><span class=\"token function\">close<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u91ca\u653e\u5b57\u7b26\u6d41\u8d44\u6e90  <\/span><br \/>\n        bos<span class=\"token punctuation\">.<\/span><span class=\"token function\">close<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u91ca\u653e\u7f13\u51b2\u6d41\u8d44\u6e90  <\/span><br \/>\n        socket<span class=\"token punctuation\">.<\/span><span class=\"token function\">close<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u91ca\u653eSocket\u8d44\u6e90&#xff0c;\u81ea\u52a8\u5173\u95ed\u5e95\u5c42\u7684\u5b57\u8282\u8f93\u5165\u6d41\u548c\u5b57\u8282\u8f93\u51fa\u6d41  <\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u521b\u5efaTCP\u63a5\u6536\u6d88\u606f\u7684\u7a0b\u5e8f\u6b65\u9aa4\u4e3a&#xff1a;<\/p>\n<li>\u521b\u5efa\u4e00\u4e2a\u63a5\u6536\u6570\u636e\u7684\u901a\u4fe1\u7aef\u70b9\u3002\u4e0eUDP\u4e0d\u540c&#xff0c;TCP\u7684\u670d\u52a1\u7aef\u91c7\u7528\u4e0e\u5ba2\u6237\u7aef\u4e0d\u540c\u7684\u7c7bServerSocket\u3002\u7aef\u53e3\u53f7\u4e0eUDP\u534f\u8bae\u76f8\u4f3c&#xff0c;\u8981\u4f7f\u7528\u5ba2\u6237\u7aefSocket\u76ee\u6807\u7aef\u53e3\u53f7\u76f8\u540c\u7684\u7aef\u53e3\u53f7&#xff0c;\u4e0d\u5bf9\u5e94\u5219\u63a5\u6536\u4e0d\u5230\u6570\u636e\u3002<\/li>\n<li>\u7b49\u5f85\u4e0e\u5ba2\u6237\u7aef\u5efa\u7acb\u8fde\u63a5\u3002\u8c03\u7528accept()\u65b9\u6cd5&#xff0c;\u4e00\u76f4\u76d1\u542c\u7aef\u53e3&#xff0c;\u7b49\u5f85\u5ba2\u6237\u7aef\u8fdb\u884c\u4e09\u6b21\u63e1\u624b\u5efa\u7acb\u8fde\u63a5\u3002\u5efa\u7acb\u8fde\u63a5\u4e4b\u524d&#xff0c;\u7ebf\u7a0b\u662f\u963b\u585e\u7684\u72b6\u6001\u3002\u94fe\u63a5\u5efa\u7acb\u540e&#xff0c;\u8fd4\u56de\u4e00\u4e2a\u5ba2\u6237\u7aefSocket\u5bf9\u8c61\u3002<\/li>\n<li>TCP\u5efa\u7acb\u8fde\u63a5\u540e&#xff0c;\u901a\u8fc7IO\u6d41\u4f20\u8f93\u6570\u636e\u3002\u53d1\u9001\u7aef\u662fOutput&#xff0c;\u63a5\u6536\u7aef\u662fInput\u3002\u56e0\u6b64&#xff0c;\u4eceSocket\u5bf9\u8c61\u4e2d\u83b7\u5f97IO\u57fa\u672c\u7684\u5b57\u8282\u8f93\u5165\u6d41\u3002<\/li>\n<li>\u89e3\u6790\u6570\u636e\u3002\u5b57\u8282\u8f93\u5165\u6d41\u53ef\u4ee5\u901a\u8fc7\u5b57\u7b26\u6d41\u3001\u8f6c\u6362\u6d41\u3001\u7f13\u51b2\u6d41\u7b49\u5904\u7406\u6d41&#xff0c;\u5904\u7406\u89e3\u6790\u6570\u636e\u3002<\/li>\n<li>\u91ca\u653e\u8d44\u6e90\u3002\u91ca\u653eIO\u6d41\u548cSocket\u8d44\u6e90\u3002<\/li>\n<p><span class=\"token comment\">\/\/ \u670d\u52a1\u5668\u7aef  <\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Server<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> args<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">throws<\/span> <span class=\"token class-name\">IOException<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ 1. \u521b\u5efa\u4e00\u4e2aServerSocket\u5bf9\u8c61  <\/span><br \/>\n        <span class=\"token class-name\">ServerSocket<\/span> serverSocket <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">ServerSocket<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">52522<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <\/p>\n<p>        <span class=\"token comment\">\/\/ 2. \u7b49\u5f85\u4e0e\u5ba2\u6237\u7aef\u5efa\u7acb\u8fde\u63a5  <\/span><br \/>\n        <span class=\"token class-name\">Socket<\/span> socket <span class=\"token operator\">&#061;<\/span> serverSocket<span class=\"token punctuation\">.<\/span><span class=\"token function\">accept<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u94fe\u63a5\u5efa\u7acb\u540e&#xff0c;\u8fd4\u56de\u4e00\u4e2aSocket\u5bf9\u8c61  <\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ 3. \u83b7\u5f97\u5b57\u8282\u8f93\u5165\u6d41\u5bf9\u8c61  <\/span><br \/>\n        <span class=\"token class-name\">InputStream<\/span> is <span class=\"token operator\">&#061;<\/span> socket<span class=\"token punctuation\">.<\/span><span class=\"token function\">getInputStream<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <\/p>\n<p>        <span class=\"token comment\">\/\/ 4. \u5c06\u5b57\u8282\u8f93\u5165\u6d41\u8f6c\u6362\u4e3a\u5b57\u7b26\u8f93\u5165\u6d41&#xff0c;\u8bfb\u53d6\u6570\u636e\u5e76\u6253\u5370\u6210\u5b57\u7b26\u4e32  <\/span><br \/>\n        <span class=\"token class-name\">InputStreamReader<\/span> isr <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">InputStreamReader<\/span><span class=\"token punctuation\">(<\/span>is<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">int<\/span> len <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">char<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> chs <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token keyword\">char<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">1024<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span>len <span class=\"token operator\">&#061;<\/span> isr<span class=\"token punctuation\">.<\/span><span class=\"token function\">read<\/span><span class=\"token punctuation\">(<\/span>chs<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">!&#061;<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">new<\/span> <span class=\"token class-name\">String<\/span><span class=\"token punctuation\">(<\/span>chs<span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> len<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span>  <\/p>\n<p>        <span class=\"token comment\">\/\/ \u4e00\u822c\u60c5\u51b5\u4e0b&#xff0c;\u670d\u52a1\u5668\u7aef\u4f1a\u5faa\u73af\u63a5\u6536\u591a\u4e2a\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42  <\/span><br \/>\n        <span class=\"token comment\">\/\/ \u65e0\u9700\u624b\u52a8\u5173\u95edSocket  <\/span><br \/>\n        <span class=\"token comment\">\/\/ 5. \u91ca\u653e\u8d44\u6e90  <\/span><br \/>\n        isr<span class=\"token punctuation\">.<\/span><span class=\"token function\">close<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u5173\u95ed\u5b57\u7b26\u8f93\u5165\u6d41  <\/span><br \/>\n        <span class=\"token comment\">\/\/ is.close(); \/\/ \u65e0\u9700\u624b\u52a8\u5173\u95ed\u5b57\u8282\u8f93\u5165\u6d41  <\/span><br \/>\n        socket<span class=\"token punctuation\">.<\/span><span class=\"token function\">close<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u5173\u95edSocket&#xff0c;\u4f1a\u81ea\u52a8\u5173\u95ed\u5e95\u5c42\u7684\u5b57\u8282\u8f93\u5165\u6d41\u548c\u5b57\u8282\u8f93\u51fa\u6d41  <\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>TCP\u534f\u8bae\u5efa\u7acb\u8fde\u63a5\u9700\u8981\u4e09\u6b21\u63e1\u624b&#xff0c;\u5173\u95ed\u8fde\u63a5\u9700\u8981\u56db\u6b21\u6325\u624b\u3002<\/p>\n<li>\u7b2c\u4e00\u6b21\u6325\u624b&#xff1a;\u5ba2\u6237\u7aef\u53d1\u8d77\u4fe1\u606f&#xff0c;\u8bf7\u6c42\u5173\u95ed\u8fde\u63a5\u3002<\/li>\n<li>\u7b2c\u4e8c\u6b21\u6325\u624b&#xff1a;\u670d\u52a1\u7aef\u6536\u5230\u4fe1\u606f&#xff0c;\u4f46\u662f\u6536\u5230\u5ba2\u6237\u7aef\u53d1\u9001\u5173\u95ed\u8fde\u63a5\u8bf7\u6c42\u65f6&#xff0c;\u670d\u52a1\u7aef\u8fd8\u6ca1\u6709\u5b8c\u5168\u6536\u5168\u6240\u6709\u4e4b\u524d\u53d1\u9001\u7684\u6570\u636e\u3002\u4f46\u662f&#xff0c;\u670d\u52a1\u7aef\u9700\u8981\u8ba9\u5ba2\u6237\u7aef\u77e5\u9053\u5b83\u6536\u5230\u4e86\u5173\u95ed\u8fde\u63a5\u7684\u8bf7\u6c42\u3002\u56e0\u6b64&#xff0c;\u670d\u52a1\u7aef\u4f1a\u7ed9\u5ba2\u6237\u7aef\u53d1\u9001\u786e\u8ba4\u6536\u5230\u5173\u95ed\u8bf7\u6c42\u7684\u4fe1\u606f\u3002<\/li>\n<li>\u7b2c\u4e09\u6b21\u6325\u624b&#xff1a;\u5f53\u670d\u52a1\u7aef\u63a5\u6536\u5b8c\u6240\u6709\u6570\u636e\u540e&#xff0c;\u4f1a\u518d\u6b21\u7ed9\u5ba2\u6237\u7aef\u53d1\u9001\u4e00\u6761\u4fe1\u606f&#xff0c;\u8868\u660e\u81ea\u5df1\u5df2\u7ecf\u5b89\u5168\u6536\u5230\u6240\u6709\u4f20\u8f93\u7684\u6570\u636e\u3002\u53d1\u9001\u786e\u8ba4\u5173\u95ed\u8fde\u63a5\u7684\u4fe1\u606f\u7ed9\u5ba2\u6237\u7aef&#xff0c;\u8868\u660e\u670d\u52a1\u5668\u5df2\u5c31\u7eea&#xff0c;\u51c6\u5907\u5173\u95ed\u3002<\/li>\n<li>\u7b2c\u56db\u6b21\u6325\u624b&#xff1a;\u5f53\u5ba2\u6237\u7aef\u6536\u5230\u670d\u52a1\u7aef\u53d1\u9001\u7684\u5173\u95ed\u786e\u8ba4\u8bf7\u6c42\u540e&#xff0c;\u53d1\u9001\u4e00\u4e2a\u81ea\u5df1\u5df2\u786e\u8ba4\u5173\u95ed\u8fde\u63a5\u7684\u8bf7\u6c42&#xff0c;\u53d1\u9001\u540e&#xff0c;\u5ba2\u6237\u7aef\u5173\u95ed\u8fde\u63a5\u3002\u800c\u670d\u52a1\u5668\u6536\u5230\u4fe1\u606f\u540e&#xff0c;\u4e5f\u5173\u95ed\u8fde\u63a5\u3002<\/li>\n","protected":false},"excerpt":{"rendered":"<p>\u4ec0\u4e48\u662f\u7f51\u7edc\u7f16\u7a0b<br \/>\n\u4ec0\u4e48\u662f\u7f51\u7edc\u7f16\u7a0b&#xff0c;\u76f8\u6bd4\u4e8e\u7f16\u5199\u7a0b\u5e8f\u5728\u672c\u673a\u4e0a\u8fd0\u884c&#xff0c;\u7f51\u7edc\u7f16\u7a0b\u662f\u6307\u7f16\u5199\u4e24\u53f0\u4e0d\u540c\u7684\u8ba1\u7b97\u673a\u7684\u7a0b\u5e8f&#xff0c;\u57fa\u4e8e\u7f51\u7edc\u534f\u8bae&#xff0c;\u901a\u8fc7\u7f51\u7edc\u8fdb\u884c\u6570\u636e\u901a\u4fe1\u3002<br \/>\n\u5e38\u89c1\u7684\u7f51\u7edc\u7a0b\u5e8f\u8f6f\u4ef6\u67b6\u6784\u6709&#xff1a;BS&#xff08;Broser\u6d4f\u89c8\u5668\/Server\u670d\u52a1\u5668&#xff09;\u67b6\u6784\u3001CS&#xff08;Client\u5ba2\u6237\u7aef\/Server\u670d\u52a1\u5668&#xff09;\u67b6\u6784<br \/>\nBS\u67b6\u6784&#xff1a;\u4f18\u52bf\u662f\u7528\u6237\u4e0d\u7528\u4e0b\u8f7d\u5ba2\u6237\u7aef&#xff0c;\u4f7f\u7528\u6d4f\u89c8\u5668\u5373\u53ef\u5feb<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,371,78],"topic":[],"class_list":["post-63470","post","type-post","status-publish","format-standard","hentry","category-server","tag-java","tag-371","tag-78"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java\u7f51\u7edc\u7f16\u7a0b\u5b66\u4e60\u7b14\u8bb0\uff0c\u4ece\u7f51\u7edc\u7f16\u7a0b\u4e09\u8981\u7d20\u5230TCP\/UDP\u534f\u8bae - \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\/63470.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java\u7f51\u7edc\u7f16\u7a0b\u5b66\u4e60\u7b14\u8bb0\uff0c\u4ece\u7f51\u7edc\u7f16\u7a0b\u4e09\u8981\u7d20\u5230TCP\/UDP\u534f\u8bae - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4ec0\u4e48\u662f\u7f51\u7edc\u7f16\u7a0b \u4ec0\u4e48\u662f\u7f51\u7edc\u7f16\u7a0b&#xff0c;\u76f8\u6bd4\u4e8e\u7f16\u5199\u7a0b\u5e8f\u5728\u672c\u673a\u4e0a\u8fd0\u884c&#xff0c;\u7f51\u7edc\u7f16\u7a0b\u662f\u6307\u7f16\u5199\u4e24\u53f0\u4e0d\u540c\u7684\u8ba1\u7b97\u673a\u7684\u7a0b\u5e8f&#xff0c;\u57fa\u4e8e\u7f51\u7edc\u534f\u8bae&#xff0c;\u901a\u8fc7\u7f51\u7edc\u8fdb\u884c\u6570\u636e\u901a\u4fe1\u3002 \u5e38\u89c1\u7684\u7f51\u7edc\u7a0b\u5e8f\u8f6f\u4ef6\u67b6\u6784\u6709&#xff1a;BS&#xff08;Broser\u6d4f\u89c8\u5668\/Server\u670d\u52a1\u5668&#xff09;\u67b6\u6784\u3001CS&#xff08;Client\u5ba2\u6237\u7aef\/Server\u670d\u52a1\u5668&#xff09;\u67b6\u6784 BS\u67b6\u6784&#xff1a;\u4f18\u52bf\u662f\u7528\u6237\u4e0d\u7528\u4e0b\u8f7d\u5ba2\u6237\u7aef&#xff0c;\u4f7f\u7528\u6d4f\u89c8\u5668\u5373\u53ef\u5feb\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/63470.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-21T16:48:50+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"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\/63470.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/63470.html\",\"name\":\"Java\u7f51\u7edc\u7f16\u7a0b\u5b66\u4e60\u7b14\u8bb0\uff0c\u4ece\u7f51\u7edc\u7f16\u7a0b\u4e09\u8981\u7d20\u5230TCP\/UDP\u534f\u8bae - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-21T16:48:50+00:00\",\"dateModified\":\"2026-01-21T16:48:50+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/63470.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/63470.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/63470.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\u7f51\u7edc\u7f16\u7a0b\u5b66\u4e60\u7b14\u8bb0\uff0c\u4ece\u7f51\u7edc\u7f16\u7a0b\u4e09\u8981\u7d20\u5230TCP\/UDP\u534f\u8bae\"}]},{\"@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":"Java\u7f51\u7edc\u7f16\u7a0b\u5b66\u4e60\u7b14\u8bb0\uff0c\u4ece\u7f51\u7edc\u7f16\u7a0b\u4e09\u8981\u7d20\u5230TCP\/UDP\u534f\u8bae - \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\/63470.html","og_locale":"zh_CN","og_type":"article","og_title":"Java\u7f51\u7edc\u7f16\u7a0b\u5b66\u4e60\u7b14\u8bb0\uff0c\u4ece\u7f51\u7edc\u7f16\u7a0b\u4e09\u8981\u7d20\u5230TCP\/UDP\u534f\u8bae - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4ec0\u4e48\u662f\u7f51\u7edc\u7f16\u7a0b \u4ec0\u4e48\u662f\u7f51\u7edc\u7f16\u7a0b&#xff0c;\u76f8\u6bd4\u4e8e\u7f16\u5199\u7a0b\u5e8f\u5728\u672c\u673a\u4e0a\u8fd0\u884c&#xff0c;\u7f51\u7edc\u7f16\u7a0b\u662f\u6307\u7f16\u5199\u4e24\u53f0\u4e0d\u540c\u7684\u8ba1\u7b97\u673a\u7684\u7a0b\u5e8f&#xff0c;\u57fa\u4e8e\u7f51\u7edc\u534f\u8bae&#xff0c;\u901a\u8fc7\u7f51\u7edc\u8fdb\u884c\u6570\u636e\u901a\u4fe1\u3002 \u5e38\u89c1\u7684\u7f51\u7edc\u7a0b\u5e8f\u8f6f\u4ef6\u67b6\u6784\u6709&#xff1a;BS&#xff08;Broser\u6d4f\u89c8\u5668\/Server\u670d\u52a1\u5668&#xff09;\u67b6\u6784\u3001CS&#xff08;Client\u5ba2\u6237\u7aef\/Server\u670d\u52a1\u5668&#xff09;\u67b6\u6784 BS\u67b6\u6784&#xff1a;\u4f18\u52bf\u662f\u7528\u6237\u4e0d\u7528\u4e0b\u8f7d\u5ba2\u6237\u7aef&#xff0c;\u4f7f\u7528\u6d4f\u89c8\u5668\u5373\u53ef\u5feb","og_url":"https:\/\/www.wsisp.com\/helps\/63470.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-21T16:48:50+00:00","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\/63470.html","url":"https:\/\/www.wsisp.com\/helps\/63470.html","name":"Java\u7f51\u7edc\u7f16\u7a0b\u5b66\u4e60\u7b14\u8bb0\uff0c\u4ece\u7f51\u7edc\u7f16\u7a0b\u4e09\u8981\u7d20\u5230TCP\/UDP\u534f\u8bae - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-21T16:48:50+00:00","dateModified":"2026-01-21T16:48:50+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/63470.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/63470.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/63470.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Java\u7f51\u7edc\u7f16\u7a0b\u5b66\u4e60\u7b14\u8bb0\uff0c\u4ece\u7f51\u7edc\u7f16\u7a0b\u4e09\u8981\u7d20\u5230TCP\/UDP\u534f\u8bae"}]},{"@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\/63470","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=63470"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/63470\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=63470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=63470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=63470"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=63470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}