{"id":10357,"date":"2025-04-18T17:58:27","date_gmt":"2025-04-18T09:58:27","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/10357.html"},"modified":"2025-04-18T17:58:27","modified_gmt":"2025-04-18T09:58:27","slug":"%e3%80%90javaee%e5%88%9d%e9%98%b6%e3%80%91%e6%b7%b1%e5%85%a5%e7%90%86%e8%a7%a3%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b-%e4%bd%bf%e7%94%a8udp%e5%8d%8f%e8%ae%aeapi%e5%ae%9e%e7%8e%b0%e5%9b%9e","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/10357.html","title":{"rendered":"\u3010JavaEE\u521d\u9636\u3011\u6df1\u5165\u7406\u89e3\u7f51\u7edc\u7f16\u7a0b\u2014\u4f7f\u7528UDP\u534f\u8baeAPI\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1080\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418095823-6802223fdd346.jpg\" width=\"1200\" \/><\/p>\n<p><span style=\"color:#956fe7\">\u524d\u8a00<\/span><\/p>\n<p><span style=\"color:#38d8f0\">&#x1f31f;&#x1f31f;\u672c\u671f\u8bb2\u89e3\u5173\u4e8eTCP\/UDP\u534f\u8bae\u7684\u539f\u7406\u7406\u89e3~~~<\/span><\/p>\n<p><span style=\"color:#38d8f0\">&#x1f308;\u611f\u5174\u8da3\u7684\u5c0f\u4f19\u4f34\u770b\u4e00\u770b\u5c0f\u7f16\u4e3b\u9875&#xff1a;GGBondlctrl-CSDN\u535a\u5ba2<\/span><\/p>\n<p><span style=\"color:#38d8f0\">&#x1f525; \u4f60\u7684\u70b9\u8d5e\u5c31\u662f\u5c0f\u7f16\u4e0d\u65ad\u66f4\u65b0\u7684\u6700\u5927\u52a8\u529b \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<\/span><\/p>\n<p><span style=\"color:#38d8f0\">&#x1f386;\u90a3\u4e48\u5e9f\u8bdd\u4e0d\u591a\u8bf4\u76f4\u63a5\u5f00\u6574\u5427~~~<\/span><\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418095824-6802224067a32.gif\" \/><\/p>\n<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"1.UDP%E7%9A%84API%E4%BD%BF%E7%94%A8%C2%A0-toc\" style=\"margin-left:40px\">1.UDP\u7684API\u4f7f\u7528\u00a0<\/p>\n<p id=\"1.1DatagramSocket-toc\" style=\"margin-left:80px\">1.1DatagramSocket<\/p>\n<p id=\"1.2DatagramPacket%C2%A0-toc\" style=\"margin-left:80px\">1.2DatagramPacket\u00a0<\/p>\n<p id=\"2.%E5%AE%9E%E7%8E%B0%E5%9B%9E%E6%98%BE%E6%9C%8D%E5%8A%A1%E5%99%A8-toc\" style=\"margin-left:40px\">2.\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668<\/p>\n<p id=\"2.1%E6%A6%82%E5%BF%B5-toc\" style=\"margin-left:80px\">2.1\u6982\u5ff5<\/p>\n<p id=\"2.2%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%9A%84%E6%93%8D%E4%BD%9C%E8%BF%87%E7%A8%8B-toc\" style=\"margin-left:80px\">2.2\u670d\u52a1\u5668\u7684\u64cd\u4f5c\u8fc7\u7a0b<\/p>\n<p id=\"1.%E5%88%9D%E5%A7%8B%E5%8C%96%E6%9C%8D%E5%8A%A1%E5%99%A8-toc\" style=\"margin-left:120px\">1.\u521d\u59cb\u5316\u670d\u52a1\u5668<\/p>\n<p id=\"2.%E8%AF%BB%E5%8F%96%E8%AF%B7%E6%B1%82%E5%B9%B6%E8%A7%A3%E6%9E%90-toc\" style=\"margin-left:120px\">2.\u8bfb\u53d6\u8bf7\u6c42\u5e76\u89e3\u6790<\/p>\n<p id=\"3.%E6%A0%B9%E6%8D%AE%E8%AF%B7%E6%B1%82%E5%AE%9E%E7%8E%B0%E5%93%8D%E5%BA%94-toc\" style=\"margin-left:120px\">3.\u6839\u636e\u8bf7\u6c42\u5b9e\u73b0\u54cd\u5e94<\/p>\n<p id=\"4.%E6%8A%8A%E5%93%8D%E5%BA%94%E8%BF%94%E5%9B%9E%E7%BB%99%E5%AE%A2%E6%88%B7%E7%AB%AF-toc\" style=\"margin-left:120px\">4.\u628a\u54cd\u5e94\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef<\/p>\n<p id=\"5.%E5%AE%A2%E6%88%B7%E7%AB%AF%E7%9A%84IP%E5%92%8C%E7%AB%AF%E5%8F%A3%E5%8F%B7%E6%89%93%E5%8D%B0-toc\" style=\"margin-left:120px\">5.\u5ba2\u6237\u7aef\u7684IP\u548c\u7aef\u53e3\u53f7\u6253\u5370<\/p>\n<p id=\"6.%E4%B8%BB%E5%87%BD%E6%95%B0%E7%9A%84%E5%AE%9E%E7%8E%B0-toc\" style=\"margin-left:120px\">6.\u4e3b\u51fd\u6570\u7684\u5b9e\u73b0<\/p>\n<p id=\"2.3%E5%AE%A2%E6%88%B7%E7%AB%AF%E7%9A%84%E6%93%8D%E4%BD%9C%E8%BF%87%E7%A8%8B-toc\" style=\"margin-left:80px\">2.3\u5ba2\u6237\u7aef\u7684\u64cd\u4f5c\u8fc7\u7a0b<\/p>\n<p id=\"1.%E5%88%9D%E5%A7%8B%E5%8C%96%E5%AE%A2%E6%88%B7%E7%AB%AF-toc\" style=\"margin-left:120px\">1.\u521d\u59cb\u5316\u5ba2\u6237\u7aef<\/p>\n<p id=\"2.%E6%8E%A7%E5%88%B6%E5%8F%B0%E8%BE%93%E5%85%A5%E8%AF%B7%E6%B1%82-toc\" style=\"margin-left:120px\">2.\u63a7\u5236\u53f0\u8f93\u5165\u8bf7\u6c42<\/p>\n<p id=\"3.%E6%9E%84%E9%80%A0%E8%AF%B7%E6%B1%82%E5%B9%B6%E4%B8%94%E5%8F%91%E9%80%81-toc\" style=\"margin-left:120px\">3.\u6784\u9020\u8bf7\u6c42\u5e76\u4e14\u53d1\u9001<\/p>\n<p id=\"4.%E8%AF%BB%E5%8F%96%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%9A%84%E5%93%8D%E5%BA%94-toc\" style=\"margin-left:120px\">4.\u8bfb\u53d6\u670d\u52a1\u5668\u7684\u54cd\u5e94<\/p>\n<p id=\"5.%E4%B8%BB%E5%87%BD%E6%95%B0%E7%9A%84%E5%AE%9E%E7%8E%B0-toc\" style=\"margin-left:120px\">5.\u4e3b\u51fd\u6570\u7684\u5b9e\u73b0<\/p>\n<p id=\"2.4%E5%9B%9E%E6%98%BE%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%9F%BA%E6%9C%AC%E6%B5%81%E7%A8%8B-toc\" style=\"margin-left:80px\">2.4\u56de\u663e\u670d\u52a1\u5668\u57fa\u672c\u6d41\u7a0b<\/p>\n<p id=\"2.5%E6%89%93%E5%8D%B0%E6%97%A5%E5%BF%97%E5%88%86%E6%9E%90-toc\" style=\"margin-left:80px\">2.5\u6253\u5370\u65e5\u5fd7\u5206\u6790<\/p>\n<p id=\"3.%E6%80%BB%E7%BB%93-toc\" style=\"margin-left:40px\">3.\u603b\u7ed3<\/p>\n<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418095824-6802224072d02.gif\" \/>\u00a0<\/p>\n<h3 id=\"1.UDP%E7%9A%84API%E4%BD%BF%E7%94%A8%C2%A0\">1.UDP\u7684API\u4f7f\u7528\u00a0<\/h3>\n<h4 id=\"1.1DatagramSocket\">1.1DatagramSocket<\/h4>\n<p>\u8fd9\u91cc\u8d1f\u8d23\u5bf9Socket\u8fdb\u884c\u8bfb\u5199&#xff0c;\u501f\u52a9\u7f51\u5361\u8fdb\u884c\u6570\u636e\u7684\u8bfb\u5199\u64cd\u4f5c&#xff1b;<\/p>\n<p>\u8fd9\u91cc\u7684\u521d\u59cb\u5316\u65b9\u6cd5\u6709\u4ee5\u4e0b\u51e0\u79cd&#xff1a;<\/p>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:500px\">\n<tbody>\n<tr>\n<td>DatagramSocket()<\/td>\n<td>\u521b\u5efa\u4e00\u4e2aUDP\u6570\u636e\u62a5\u5957\u63a5\u5b57Socket&#xff0c;\u7ed1\u5b9a\u5230\u672c\u673a\u7684\u968f\u610f\u7684\u4e00\u4e2a\u7aef\u53e3&#xff08;\u5ba2\u6237\u7aef&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>DatagramSocket(int port)<\/td>\n<td>\u521b\u5efa\u4e00\u4e2aUDP\u6570\u636e\u62a5\u5957\u63a5\u5b57Socket&#xff0c;\u7ed1\u5b9a\u5230\u672c\u673a\u7684\u6307\u5b9a\u7684\u4e00\u4e2a\u7aef\u53e3&#xff08;\u670d\u52a1\u5668&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0\u8fd8\u5305\u62ec\u5b9e\u73b0\u90a3\u5957\u63a5\u5b57\u7684\u65b9\u6cd5&#xff1a;<\/p>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:500px\">\n<tbody>\n<tr>\n<td>receive&#xff08;DatagramPacket p&#xff09;<\/td>\n<td>\u4f7f\u7528\u5957\u63a5\u5b57\u5b9e\u73b0\u6570\u636e\u7684\u8bfb\u53d6<\/td>\n<\/tr>\n<tr>\n<td>send&#xff08;DatagramPacket p&#xff09;<\/td>\n<td>\u4f7f\u7528\u5957\u63a5\u5b57\u5b9e\u73b0\u6570\u636e\u7684\u5199\u5165<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6ce8\u610f&#xff1a;\u8fd9\u91cc\u7684<span style=\"color:#fe2c24\">DatagramPacket\u5c31\u662f\u4e00\u4e2a\u8f93\u51fa\u578b\u53c2\u6570<\/span>\u00a0<\/p>\n<h4 id=\"1.2DatagramPacket%C2%A0\">1.2DatagramPacket\u00a0<\/h4>\n<p>\u00a0 \u00a0 \u00a0 \u00a0\u63a5\u7740\u4e0a\u9762&#xff0c;\u5c0f\u7f16\u63d0\u5230\u8fd9\u91cc\u7684DatagramPacket\u662f\u4e00\u4e2a\u8f93\u51fa\u578b\u53c2\u6570&#xff0c;\u548c\u524d\u9762\u5b9e\u73b0\u6587\u4ef6IO\u7684\u64cd\u4f5c\u7c7b\u4f3c\u7684&#xff0c;<span style=\"color:#fe2c24\">\u8fd9\u91cc\u7684\u5c31\u662f\u4e00\u4e2aUDP\u6570\u636e\u62a5&#xff0c;\u662f\u63a5\u6536\u548c\u53d1\u9001\u6570\u636e\u7684\u57fa\u672c\u5355\u4f4d&#xff1b;<\/span><\/p>\n<h3 id=\"2.%E5%AE%9E%E7%8E%B0%E5%9B%9E%E6%98%BE%E6%9C%8D%E5%8A%A1%E5%99%A8\">2.\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668<\/h3>\n<h4 id=\"2.1%E6%A6%82%E5%BF%B5\">2.1\u6982\u5ff5<\/h4>\n<p>\u56de\u663e\u670d\u52a1\u5668&#xff1a;\u76f8\u5f53\u4e8e\u6211\u4eec\u4e4b\u524d\u5b66\u4e60\u7684\u8f93\u51fahello world&#xff0c;\u8fd9\u91cc\u7684\u56de\u663e\u670d\u52a1\u5668\u4ee3\u8868\u7684\u662f\u6ca1\u6709\u4efb\u4f55\u903b\u8f91\u8fc7\u7a0b&#xff0c;\u5373\u5ba2\u6237\u7aef\u8bf7\u6c42\u5565\u5c31\u76f4\u63a5\u54cd\u5e94\u5565&#xff1b;<\/p>\n<h4 id=\"2.2%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%9A%84%E6%93%8D%E4%BD%9C%E8%BF%87%E7%A8%8B\">2.2\u670d\u52a1\u5668\u7684\u64cd\u4f5c\u8fc7\u7a0b<\/h4>\n<h5 id=\"1.%E5%88%9D%E5%A7%8B%E5%8C%96%E6%9C%8D%E5%8A%A1%E5%99%A8\" style=\"background-color:transparent\">1.\u521d\u59cb\u5316\u670d\u52a1\u5668<\/h5>\n<p>\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>public class UDPServer {<br \/>\n    \/\/\u6784\u9020\u65b9\u6cd5<br \/>\n     private DatagramSocket socket&#061;null;<br \/>\n     public UDPServer(int port) throws SocketException {<br \/>\n        \/\/\u901a\u8fc7socket\u5bf9\u7f51\u5361\u8fdb\u884c\u6570\u636e\u7684\u64cd\u4f5c<br \/>\n        socket&#061;new DatagramSocket(port);<br \/>\n    } <\/p>\n<p><span style=\"color:#fe2c24\">\u6ce8\u610f<\/span>&#xff1a;<\/p>\n<p>1.\u6211\u4eec\u6240\u6709\u7684\u5bf9\u4e8e\u7f51\u5361\u7684\u64cd\u4f5c\u5c31\u662f\u501f\u7528\u8fd9\u91cc\u7684socket\u5b9e\u73b0&#xff0c;\u8fd9\u91cc\u7684port\u662f\u4e00\u4e2a\u7aef\u53e3\u53f7&#xff0c;\u670d\u52a1\u5668\u662f\u53ef\u63a7\u7684\u6240\u4ee5\u8fd9\u91cc\u5c31\u8981\u6307\u5b9a\u4e00\u4e2a\u7aef\u53e3\u53f7&#xff1b;<\/p>\n<p>2.\u629b\u51fa\u5f02\u5e38&#xff0c;\u5f53\u7aef\u53e3\u53f7\u88ab\u4e00\u4e2a\u8fdb\u7a0b\u5360\u7528\u4e86&#xff0c;\u90a3\u4e48\u7aef\u53e3\u53f7\u5c31\u521b\u5efa\u5931\u8d25\u4e86&#xff0c;\u4e00\u4e2a\u7aef\u53e3\u53f7\u53ea\u80fd\u88ab\u4e00\u4e2a\u8fdb\u7a0b\u5360\u7528&#xff0c;\u4f46\u662f\u4e00\u4e2a\u8fdb\u7a0b\u53ef\u4ee5\u5360\u7528\u591a\u4e2a\u7aef\u53e3\u53f7&#xff1b;<\/p>\n<h5 id=\"2.%E8%AF%BB%E5%8F%96%E8%AF%B7%E6%B1%82%E5%B9%B6%E8%A7%A3%E6%9E%90\">2.\u8bfb\u53d6\u8bf7\u6c42\u5e76\u89e3\u6790<\/h5>\n<p>\u4ee3\u7801\u5982\u4e0b&#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            \/\/ \u6bcf\u6b21\u5faa\u73af, \u5c31\u662f\u5904\u7406\u4e00\u4e2a\u8bf7\u6c42-\u54cd\u5e94\u8fc7\u7a0b.<br \/>\n            \/\/ 1. \u8bfb\u53d6\u8bf7\u6c42\u5e76\u89e3\u6790<br \/>\n            DatagramPacket requestPacket &#061; new DatagramPacket(new byte[4096], 4096);<br \/>\n            socket.receive(requestPacket);<br \/>\n            \/\/ \u8bfb\u5230\u7684\u5b57\u8282\u6570\u7ec4, \u8f6c\u6210 String \u65b9\u4fbf\u540e\u7eed\u7684\u903b\u8f91\u5904\u7406.<br \/>\n            String request &#061; new String(requestPacket.getData(), 0, requestPacket.getLength()); <\/p>\n<p><span style=\"color:#fe2c24\">\u6ce8\u610f&#xff1a;<\/span><\/p>\n<p>1.\u8fd9\u91cc\u7684\u6b7b\u5faa\u73af\u662f\u4e3a\u4e86\u8868\u793a&#xff0c;\u670d\u52a1\u5668\u662f24\u5c0f\u65f6\u4e0d\u95f4\u65ad\u7684&#xff0c;\u6240\u4ee5\u6ca1\u6709\u5fc5\u8981\u8fdb\u884c\u9000\u51fa\u7684\u64cd\u4f5c&#xff1b;<\/p>\n<p>2.\u901a\u8fc7DatagramPacket\u8bbe\u7f6e\u4fdd\u5b58\u8fd9\u91cc\u7684\u8bfb\u53d6\u5230\u7684\u5b57\u8282\u4fe1\u606f&#xff0c;\u8fd9\u662f\u4e00\u4e2a\u8f93\u51fa\u578b\u53c2\u6570&#xff1b;<\/p>\n<p>3.\u6b64\u65f6\u7684receive\u5c31\u80fd\u8bfb\u53d6\u5230UDP\u6570\u636e\u62a5\u7684\u7684\u5185\u5bb9&#xff0c;\u5b58\u653e\u5230requestPacket\u5b57\u8282\u6570\u7ec4\u4e2d&#xff1b;\u5e76\u4e14\u8fd9\u91cc\u8fd8\u77e5\u9053\u539fIP\u7aef\u53e3\u662f\u5565&#xff08;\u5373\u6570\u636e\u4ece\u54ea\u91cc\u6765\u7684&#xff09;<\/p>\n<p>4.\u6700\u540e\u5c06\u8fd9\u91cc\u7684\u5b57\u8282\u7c7b\u578b\u7684\u6570\u636e\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32\u7c7b\u578b\u7684\u6570\u636e&#xff0c;\u5b57\u8282\u6570\u7ec4\u91cc\u4e0d\u4e00\u5b9a\u5c31\u662f\u4e8c\u8fdb\u5236\u7684\u6570\u636e&#xff0c;\u8fd8\u53ef\u80fd\u662f\u6587\u672c\u7c7b\u578b\u7684\u6570\u636e&#xff0c;\u4f7f\u7528string\u4fdd\u5b58\u6070\u5230\u597d\u5904&#xff1b;<\/p>\n<h5 id=\"3.%E6%A0%B9%E6%8D%AE%E8%AF%B7%E6%B1%82%E5%AE%9E%E7%8E%B0%E5%93%8D%E5%BA%94\">3.\u6839\u636e\u8bf7\u6c42\u5b9e\u73b0\u54cd\u5e94<\/h5>\n<p>\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p> String response &#061; process(request);<\/p>\n<p> public String process(String request) {<br \/>\n        return request;<br \/>\n    } <\/p>\n<p><span style=\"color:#fe2c24\">\u6ce8\u610f&#xff1a;<\/span><\/p>\n<p>\u7531\u4e8e\u56de\u663e\u670d\u52a1\u5668\u662f\u6ca1\u6709\u4e1a\u52a1\u903b\u8f91\u7684&#xff0c;\u6240\u4ee5\u5728\u5b9e\u73b0\u5bf9\u5e94\u7684\u54cd\u5e94\u7684\u65f6\u5019&#xff0c;\u76f4\u63a5\u653e\u56de\u8f93\u51fa\u7684\u8bf7\u6c42\u5373\u53ef<\/p>\n<h5 id=\"4.%E6%8A%8A%E5%93%8D%E5%BA%94%E8%BF%94%E5%9B%9E%E7%BB%99%E5%AE%A2%E6%88%B7%E7%AB%AF\">4.\u628a\u54cd\u5e94\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef<\/h5>\n<p>\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p> \/\/ 3. \u628a\u54cd\u5e94\u8fd4\u56de\u5230\u5ba2\u6237\u7aef.<br \/>\n \/\/    \u6784\u9020\u4e00\u4e2a DatagramPacket \u4f5c\u4e3a\u54cd\u5e94\u5bf9\u8c61<br \/>\n            DatagramPacket responsePacket &#061; new DatagramPacket(response.getBytes(), response.getBytes().length,<br \/>\n            requestPacket.getSocketAddress());<br \/>\n            socket.send(responsePacket); <\/p>\n<p><span style=\"color:#fe2c24\">\u6ce8\u610f<\/span>&#xff1a;<\/p>\n<p>1.\u8fd9\u91cc\u7684\u5b9e\u73b0\u5bf9\u4e8e\u5b57\u7b26\u4e32\u7684\u64cd\u4f5c&#xff0c;\u628astring\u7684\u5b57\u8282\u6570\u7ec4\u7ed9\u63d0\u53d6\u51fa\u6765&#xff1b;<\/p>\n<p>2.\u8fd9\u91cc\u8fd8\u4f7f\u7528\u4e86socketAddress\u5b9e\u73b0&#xff0c;\u5f97\u5230INetAddress\u5bf9\u8c61&#xff0c;\u5305\u542b\u4e86\u5ba2\u6237\u7aef\u7684\u7684IP\u548c\u7aef\u53e3\u53f7&#xff0c;\u5373\u5ba2\u6237\u7aef\u7684\u6570\u636e\u62a5&#xff1b;<\/p>\n<h5 id=\"5.%E5%AE%A2%E6%88%B7%E7%AB%AF%E7%9A%84IP%E5%92%8C%E7%AB%AF%E5%8F%A3%E5%8F%B7%E6%89%93%E5%8D%B0\" style=\"background-color:transparent\">5.\u5ba2\u6237\u7aef\u7684IP\u548c\u7aef\u53e3\u53f7\u6253\u5370<\/h5>\n<p>\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>  System.out.printf(&#034;[%s:%d] req: %s, resp: %s\\\\n&#034;, requestPacket.getAddress().toString(),<br \/>\n                    requestPacket.getPort(), request, respond); <\/p>\n<p><span style=\"color:#fe2c24\">\u6ce8\u610f&#xff1a;<\/span><\/p>\n<p>\u8fd9\u91cc\u4ee3\u8868\u7684\u5c31\u662f\u5ba2\u6237\u7aef\u7684IP,\u7aef\u53e3\u53f7&#xff0c;\u4ee5\u53ca\u8bf7\u6c42\u548c\u54cd\u5e94&#xff1b;<\/p>\n<h5 id=\"6.%E4%B8%BB%E5%87%BD%E6%95%B0%E7%9A%84%E5%AE%9E%E7%8E%B0\">6.\u4e3b\u51fd\u6570\u7684\u5b9e\u73b0<\/h5>\n<p>\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>public static void main(String[] args) throws IOException {<br \/>\n        UDPServer udpServer&#061;new UDPServer(9090);<br \/>\n        udpServer.start();<br \/>\n    } <\/p>\n<p><span style=\"color:#fe2c24\">\u6ce8\u610f&#xff1a;<\/span><\/p>\n<p>\u00a0\u8fd9\u91cc\u76849090\u662f\u6211\u4eec\u7a0b\u5e8f\u5458\u89c4\u5b9a\u7684\u670d\u52a1\u5668\u7684\u7aef\u53e3\u53f7&#xff1b;<\/p>\n<h4 id=\"2.3%E5%AE%A2%E6%88%B7%E7%AB%AF%E7%9A%84%E6%93%8D%E4%BD%9C%E8%BF%87%E7%A8%8B\" style=\"background-color:transparent\">2.3\u5ba2\u6237\u7aef\u7684\u64cd\u4f5c\u8fc7\u7a0b<\/h4>\n<h5 id=\"1.%E5%88%9D%E5%A7%8B%E5%8C%96%E5%AE%A2%E6%88%B7%E7%AB%AF\">1.\u521d\u59cb\u5316\u5ba2\u6237\u7aef<\/h5>\n<p>\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>public class UDPClient {<br \/>\n    private DatagramSocket socket&#061;null;<br \/>\n    private String ServerIP;<br \/>\n    private int ServerPort;<br \/>\n    public UDPClient(String serverIP,int serverPort) throws SocketException {<br \/>\n        this.ServerIP&#061; serverIP;<br \/>\n        this.ServerPort&#061;serverPort;<br \/>\n        socket&#061;new DatagramSocket();<br \/>\n    } <\/p>\n<p><span style=\"color:#fe2c24\">\u6ce8\u610f&#xff1a;<\/span><\/p>\n<p>\u8fd9\u91cc\u8981\u8bbe\u7f6e\u8981\u8bf7\u6c42\u7684\u670d\u52a1\u5668\u7684IP\u548c\u7aef\u53e3\u53f7&#xff0c;\u56e0\u4e3a\u53d1\u8d77\u8bf7\u6c42\u5c31\u662f\u8981\u77e5\u9053\u670d\u52a1\u5668\u5728\u54ea\u91cc&#xff1b;\u8fd9\u91cc\u548c\u4e0a\u9762\u65e5\u5fd7\u7684\u6253\u5370\u662f\u4e00\u81f4\u7684&#xff0c;\u8bf7\u6c42\u7684IP\u662f\u5ba2\u6237\u7aef\u7684\u672c\u673aIP&#xff0c;\u5ba2\u6237\u7aef\u662f\u7cfb\u7edf\u968f\u673a\u5206\u914d\u7684&#xff1b;<\/p>\n<h5 id=\"2.%E6%8E%A7%E5%88%B6%E5%8F%B0%E8%BE%93%E5%85%A5%E8%AF%B7%E6%B1%82\">2.\u63a7\u5236\u53f0\u8f93\u5165\u8bf7\u6c42<\/h5>\n<p>\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p> public void start() throws IOException {<br \/>\n        System.out.println(&#034;\u5ba2\u6237\u7aef\u542f\u52a8&#034;);<br \/>\n        Scanner sc&#061;new Scanner(System.in);<br \/>\n        while (true){<br \/>\n            System.out.println(&#034;-&gt;&#034;);<br \/>\n            if (!sc.hasNext()){<br \/>\n                break;<br \/>\n            } <\/p>\n<p><span style=\"color:#fe2c24\">\u6ce8\u610f&#xff1a;<\/span><\/p>\n<p>\u8fd9\u91cc\u548c\u670d\u52a1\u5668\u662f\u4e00\u81f4\u7684&#xff0c;\u90fd\u662f24\u5c0f\u65f6\u4e0d\u95f4\u65ad\u7684&#xff0c;\u8fd9\u91cc\u7684sc.hashnext\u662f\u4e3a\u4e86\u8868\u793a\u6ca1\u6709\u66f4\u591a\u7684\u7684\u8f93\u5165\u4e86&#xff0c;\u90a3\u4e48\u5c31\u8fd4\u56defalse\u53bb\u53cd\u540e\u5c31\u8df3\u51fa\u5faa\u73af&#xff1b;<\/p>\n<h5 id=\"3.%E6%9E%84%E9%80%A0%E8%AF%B7%E6%B1%82%E5%B9%B6%E4%B8%94%E5%8F%91%E9%80%81\">3.\u6784\u9020\u8bf7\u6c42\u5e76\u4e14\u53d1\u9001<\/h5>\n<p>\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>String request&#061;sc.next();<br \/>\n            DatagramPacket requestPacket&#061;new DatagramPacket(request.getBytes(),request.getBytes().length,<br \/>\n            InetAddress.getByName(ServerIP),ServerPort);<br \/>\n            \/\/\u6765\u81ea\u54ea\u91cc\u7684\u4fe1\u606f<br \/>\n            socket.send(requestPacket); <\/p>\n<p><span style=\"color:#fe2c24\">\u6ce8\u610f&#xff1a;<\/span><\/p>\n<p>\u8fd9\u91cc\u5c31\u662f\u901a\u8fc7\u5b57\u7b26\u4e32\u8f6c\u4e3a\u5b57\u8282\u6570\u636e&#xff0c;\u5e76\u4e14\u6307\u5b9a\u53d1\u9001\u7684\u7aef\u53e3\u53f7\u548cIP\u5730\u5740&#xff0c;\u6700\u540e\u901a\u8fc7send\u8fdb\u884c\u53d1\u9001\u6570\u636e&#xff0c;\u8bf7\u6c42\u670d\u52a1\u5668&#xff1b;<\/p>\n<h5 id=\"4.%E8%AF%BB%E5%8F%96%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%9A%84%E5%93%8D%E5%BA%94\">4.\u8bfb\u53d6\u670d\u52a1\u5668\u7684\u54cd\u5e94<\/h5>\n<p>\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>\/\/ 4. \u8bfb\u53d6\u670d\u52a1\u5668\u7684\u54cd\u5e94.<br \/>\n            DatagramPacket respondPacket&#061;new DatagramPacket(new byte[1024],1024);<br \/>\n            socket.receive(respondPacket);<\/p>\n<p>            String respond&#061;new String(respondPacket.getData(),0,respondPacket.getLength());<\/p>\n<p>            System.out.println(respond); <\/p>\n<p><span style=\"color:#fe2c24\">\u6ce8\u610f&#xff1a;<\/span><\/p>\n<p>\u8fd9\u91cc\u5c31\u89c4\u5b9a\u4f20\u8f93\u7684\u6570\u636e\u5355\u4f4d&#xff0c;\u901a\u8fc7\u63a5\u6536\u670d\u52a1\u5668\u4f20\u6765\u7684\u54cd\u5e94&#xff0c;\u4fdd\u5b58\u5230\u5b57\u8282\u6570\u7ec4\u91cc\u9762&#xff0c;\u6700\u540e\u8f6c\u4e3astring\u5b57\u7b26\u4e32\u7c7b\u578b\u7684\u6570\u636e&#xff0c;\u5728\u5b9e\u73b0\u6253\u5370<\/p>\n<h5 id=\"5.%E4%B8%BB%E5%87%BD%E6%95%B0%E7%9A%84%E5%AE%9E%E7%8E%B0\">5.\u4e3b\u51fd\u6570\u7684\u5b9e\u73b0<\/h5>\n<p>public static void main(String[] args) throws IOException {<br \/>\n        UDPClient udpClient&#061;new UDPClient(&#034;127.0.0.1&#034;, 9090);<br \/>\n        udpClient.start();<br \/>\n    } <\/p>\n<p><span style=\"color:#fe2c24\">\u6ce8\u610f&#xff1a;<\/span><\/p>\n<p>\u8fd9\u91cc\u7684\u201c127.0.0.1\u201d\u662f\u672c\u673a\u7684IP\u5730\u5740&#xff0c;9090\u662f\u6211\u4eec\u8f93\u5165\u7684\u670d\u52a1\u5668\u7aef\u53e3\u53f7&#xff1b;<\/p>\n<h4 id=\"2.4%E5%9B%9E%E6%98%BE%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%9F%BA%E6%9C%AC%E6%B5%81%E7%A8%8B\">2.4\u56de\u663e\u670d\u52a1\u5668\u57fa\u672c\u6d41\u7a0b<\/h4>\n<p>\u5982\u4e0b\u56fe\u7247\u7684\u5b9e\u73b0\u8fc7\u7a0b&#xff1a;<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418095824-680222407e6c0.png\" \/><\/p>\n<p>\u5c0f\u7f16\u8fd9\u91cc\u7531\u4e8e\u5bbd\u5ea6\u4e0d\u591f\u5c31\u65e0\u6cd5\u5b8c\u5168\u5206\u5f00&#xff0c;\u8bf7\u89c1\u8c05~~~\u4ee5\u4e0a\u5c31\u662f\u5177\u4f53\u7684\u5b9e\u73b0\u8fc7\u7a0b<\/p>\n<p>\u7b2c\u4e00\u6b65&#xff1a;\u670d\u52a1\u5668\u542f\u52a8\u8fdb\u5165receive&#xff0c;\u53d1\u73b0\u6ca1\u6709\u8bf7\u6c42&#xff0c;\u90a3\u4e48\u5c31\u76f4\u63a5\u8fdb\u5165\u963b\u585e&#xff1b;<\/p>\n<p>\u5177\u4f53\u4ee3\u7801&#xff1a;<\/p>\n<p> DatagramPacket requestPacket&#061;new DatagramPacket(new byte[1024],1024);<br \/>\n            \/\/\u901a\u8fc7\u63a5\u6536\u7684\u65b9\u6cd5\u8fdb\u884c\u6570\u636e\u7684\u4f20\u5165<br \/>\n            socket.receive(requestPacket); <\/p>\n<p>\u00a0\u7b2c\u4e8c\u6b65&#xff1a;\u5ba2\u6237\u7aef\u8fdb\u5165\u5faa\u73af&#xff0c;\u6267\u884c\u5230sc.hashnext\u8fdb\u5165\u963b\u585e&#xff0c;\u77e5\u9053\u7528\u6237\u8f93\u5165\u5185\u5bb9&#xff1b;<\/p>\n<p>\u5177\u4f53\u4ee3\u7801&#xff1a;<\/p>\n<p> System.out.println(&#034;-&gt;&#034;);<br \/>\n            if (!sc.hasNext()){<br \/>\n                break;<br \/>\n            } <\/p>\n<p>\u7b2c\u4e09\u6b65&#xff1a;\u8f93\u5165\u8bf7\u6c42\u7684\u5185\u5bb9&#xff0c;\u8f6c\u5316\u4e3a\u5b57\u8282\u7c7b\u578b\u6570\u636e&#xff0c;\u6307\u5b9a\u670d\u52a1\u5668IP\u548c\u7aef\u53e3\u53f7&#xff0c;\u53d1\u9001\u8bf7\u6c42<\/p>\n<p>\u5177\u4f53\u4ee3\u7801&#xff1a;<\/p>\n<p> String request&#061;sc.next();<br \/>\n            DatagramPacket requestPacket&#061;new DatagramPacket(request.getBytes(),request.getBytes().length,<br \/>\n                    InetAddress.getByName(ServerIP),ServerPort);<br \/>\n            \/\/\u6765\u81ea\u54ea\u91cc\u7684\u4fe1\u606f<br \/>\n            socket.send(requestPacket); <\/p>\n<p>\u7b2c\u56db\u6b65&#xff1a;\u670d\u52a1\u5668\u89e3\u9664\u963b\u585e&#xff0c;\u8bfb\u53d6DatagramRocket\u5bf9\u8c61&#xff0c;\u6784\u9020string\u9700\u6c42&#xff0c;\u6839\u636e\u9700\u6c42\u6267\u884c\u54cd\u5e94\u64cd\u4f5c&#xff0c;\u6700\u540e\u8fd4\u56de\u6784\u9020\u54cd\u5e94\u5bf9\u8c61&#xff0c;\u5e76\u8fdb\u884csend\u53d1\u9001\u7684\u64cd\u4f5c&#xff1b;\u8fd9\u4e2a\u8fc7\u7a0b\u5ba2\u6237\u7aef\u963b\u585e<\/p>\n<p>\u5177\u4f53\u4ee3\u7801:<\/p>\n<p> String request&#061;new String(requestPacket.getData(),0,requestPacket.getLength());<br \/>\n            \/\/\u6ce8\u610f\u8fd9\u91cc\u7684\u957f\u5ea6\u662f\u5b57\u8282\u7684\u957f\u5ea6&#xff0c;\u4e0d\u662f\u5b57\u7b26\u4e32\u7684\u957f\u5ea6<br \/>\n            \/\/\u8fdb\u884c\u54cd\u5e94\u7684\u64cd\u4f5c<br \/>\n            String respond&#061;process(request);<br \/>\n            \/\/\u53d1\u9001\u54cd\u5e94,\u8f6c\u5316\u4e3a\u9762\u5411\u6570\u636e\u5305\u7684\u7c7b\u578b<br \/>\n            DatagramPacket respondPacket&#061;new DatagramPacket(respond.getBytes(),respond.getBytes().length,<br \/>\n                    requestPacket.getSocketAddress());<br \/>\n            \/\/\u6700\u540e\u53d1\u9001\u8fd9\u4e2a\u6570\u636e<br \/>\n            socket.send(respondPacket); <\/p>\n<p>\u7b2c\u4e94\u6b65&#xff1a;\u5ba2\u6237\u7aef\u63a5\u6536\u670d\u52a1\u5668\u4f20\u6765\u7684\u6570\u636e&#xff0c;\u5b58\u50a8\u5728\u5b57\u8282\u6570\u7ec4\u4e2d&#xff0c;\u7136\u540e\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32\u6570\u636e\u7c7b\u578b&#xff0c;\u5b9e\u73b0\u6253\u5370\u5728\u63a7\u5236\u53f0\u4e0a&#xff1b;<\/p>\n<p>\u5177\u4f53\u4ee3\u7801&#xff1a;<\/p>\n<p> DatagramPacket respondPacket&#061;new DatagramPacket(new byte[1024],1024);<br \/>\n            socket.receive(respondPacket);<\/p>\n<p>            String respond&#061;new String(respondPacket.getData(),0,respondPacket.getLength());<\/p>\n<p>            System.out.println(respond); <\/p>\n<h4 id=\"2.5%E6%89%93%E5%8D%B0%E6%97%A5%E5%BF%97%E5%88%86%E6%9E%90\">2.5\u6253\u5370\u65e5\u5fd7\u5206\u6790<\/h4>\n<p>\u8fd9\u91cc\u6211\u4eec\u542f\u52a8\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u540e&#xff0c;\u8fdb\u884c\u8f93\u5165&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"287\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418095825-6802224126d7c.png\" width=\"566\" \/><\/p>\n<p>\u8fd9\u91cc\u6211\u4eec\u5c31\u53ef\u4ee5\u770b\u5230\u8f93\u51fa\u4e00\u4e2anihao\u90a3\u4e48\u5c31\u8fd4\u56de\u4e00\u4e2anihao&#xff0c;\u90a3\u4e48\u6211\u4eec\u53ef\u4ee5\u770b\u770b\u670d\u52a1\u5668\u7684\u6253\u5370\u65e5\u5fd7<\/p>\n<p>\u5982\u4e0b\u56fe&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"254\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418095825-6802224136ad9.png\" width=\"661\" \/><\/p>\n<p>\u6b64\u65f6\u6ce8\u610f\u524d\u9762\u4e24\u4e2a\u7b2c\u4e00\u4e2a\u662f\u201c127.0.0.1\u201d\u662f\u6211\u4eec\u81ea\u5df1\u7684\u672c\u673aIP\u5730\u5740&#xff0c;\u5e76\u4e14\u540e\u9762\u8fd9\u4e2a\u5c31\u662f\u8bf7\u6c42\u7684\u7aef\u53e3&#xff1b;<\/p>\n<h3 id=\"3.%E6%80%BB%E7%BB%93\">3.\u603b\u7ed3<\/h3>\n<p>\u00a0&#x1f4ac;&#x1f4ac;\u672c\u671f\u5c0f\u7f16\u4e3b\u8981\u8bb2\u89e3\u4e86UDP\u7684API\u7684\u4f7f\u7528&#xff0c;\u5e76\u4e14\u901a\u8fc7UDP\u63d0\u4f9b\u7684API\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668\u7684\u5b9e\u73b0&#xff0c;\u5f53\u7136\u8fd9\u91cc\u8bbe\u8ba1\u5230\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u4e24\u8fb9\u7684\u5b9e\u73b0\u8fc7\u7a0b~~~<\/p>\n<p>\u5177\u4f53\u4ee3\u7801\u5df2\u4e0a\u4f20gitee&#xff0c;\u4ee3\u7801\u5728\u8fd9\u91cc&#xff1a;network: \u7f51\u7edc\u7f16\u7a0b<\/p>\n<p><span style=\"color:#38d8f0\">&#x1f305;&#x1f305;&#x1f305;~~~~\u6700\u540e\u5e0c\u671b\u4e0e\u8bf8\u541b\u5171\u52c9&#xff0c;\u5171\u540c\u8fdb\u6b65&#xff01;&#xff01;\u00a0<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"313\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418095825-6802224147483.png\" width=\"450\" \/><\/p>\n<hr \/>\n<p style=\"text-align:center\"><span style=\"color:#38d8f0\">&#x1f4aa;&#x1f4aa;&#x1f4aa;\u4ee5\u4e0a\u5c31\u662f\u672c\u671f\u5185\u5bb9\u4e86&#xff0c; \u611f\u5174\u8da3\u7684\u8bdd&#xff0c;\u5c31\u5173\u6ce8\u5c0f\u7f16\u5427\u3002<\/span><\/p>\n<p style=\"text-align:center\"><span style=\"color:#38d8f0\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&#x1f60a;&#x1f60a; \u00a0\u671f\u5f85\u4f60\u7684\u5173\u6ce8~~~<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb4.9k\u6b21\uff0c\u70b9\u8d5e103\u6b21\uff0c\u6536\u85cf67\u6b21\u3002\u672c\u671f\u4e3b\u8981\u8bb2\u89e3\u4e86UDP\u7684API\u7684\u4f7f\u7528\uff0c\u5e76\u4e14\u901a\u8fc7UDP\u63d0\u4f9b\u7684API\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668\u7684\u5b9e\u73b0\uff0c\u5f53\u7136\u8fd9\u91cc\u8bbe\u8ba1\u5230\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u4e24\u8fb9\u7684\u5b9e\u73b0\u8fc7\u7a0b_api udp<\/p>\n","protected":false},"author":2,"featured_media":10350,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[358,193,441,361,78,191],"topic":[],"class_list":["post-10357","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-javaee","tag-udp","tag-udpapi","tag-361","tag-78","tag-191"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010JavaEE\u521d\u9636\u3011\u6df1\u5165\u7406\u89e3\u7f51\u7edc\u7f16\u7a0b\u2014\u4f7f\u7528UDP\u534f\u8baeAPI\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/10357.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010JavaEE\u521d\u9636\u3011\u6df1\u5165\u7406\u89e3\u7f51\u7edc\u7f16\u7a0b\u2014\u4f7f\u7528UDP\u534f\u8baeAPI\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb4.9k\u6b21\uff0c\u70b9\u8d5e103\u6b21\uff0c\u6536\u85cf67\u6b21\u3002\u672c\u671f\u4e3b\u8981\u8bb2\u89e3\u4e86UDP\u7684API\u7684\u4f7f\u7528\uff0c\u5e76\u4e14\u901a\u8fc7UDP\u63d0\u4f9b\u7684API\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668\u7684\u5b9e\u73b0\uff0c\u5f53\u7136\u8fd9\u91cc\u8bbe\u8ba1\u5230\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u4e24\u8fb9\u7684\u5b9e\u73b0\u8fc7\u7a0b_api udp\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/10357.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T09:58:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418095823-6802223fdd346.jpg\" \/>\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=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/10357.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/10357.html\",\"name\":\"\u3010JavaEE\u521d\u9636\u3011\u6df1\u5165\u7406\u89e3\u7f51\u7edc\u7f16\u7a0b\u2014\u4f7f\u7528UDP\u534f\u8baeAPI\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T09:58:27+00:00\",\"dateModified\":\"2025-04-18T09:58:27+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/10357.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/10357.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/10357.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010JavaEE\u521d\u9636\u3011\u6df1\u5165\u7406\u89e3\u7f51\u7edc\u7f16\u7a0b\u2014\u4f7f\u7528UDP\u534f\u8baeAPI\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010JavaEE\u521d\u9636\u3011\u6df1\u5165\u7406\u89e3\u7f51\u7edc\u7f16\u7a0b\u2014\u4f7f\u7528UDP\u534f\u8baeAPI\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/10357.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010JavaEE\u521d\u9636\u3011\u6df1\u5165\u7406\u89e3\u7f51\u7edc\u7f16\u7a0b\u2014\u4f7f\u7528UDP\u534f\u8baeAPI\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb4.9k\u6b21\uff0c\u70b9\u8d5e103\u6b21\uff0c\u6536\u85cf67\u6b21\u3002\u672c\u671f\u4e3b\u8981\u8bb2\u89e3\u4e86UDP\u7684API\u7684\u4f7f\u7528\uff0c\u5e76\u4e14\u901a\u8fc7UDP\u63d0\u4f9b\u7684API\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668\u7684\u5b9e\u73b0\uff0c\u5f53\u7136\u8fd9\u91cc\u8bbe\u8ba1\u5230\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u4e24\u8fb9\u7684\u5b9e\u73b0\u8fc7\u7a0b_api udp","og_url":"https:\/\/www.wsisp.com\/helps\/10357.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T09:58:27+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418095823-6802223fdd346.jpg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/10357.html","url":"https:\/\/www.wsisp.com\/helps\/10357.html","name":"\u3010JavaEE\u521d\u9636\u3011\u6df1\u5165\u7406\u89e3\u7f51\u7edc\u7f16\u7a0b\u2014\u4f7f\u7528UDP\u534f\u8baeAPI\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T09:58:27+00:00","dateModified":"2025-04-18T09:58:27+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/10357.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/10357.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/10357.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010JavaEE\u521d\u9636\u3011\u6df1\u5165\u7406\u89e3\u7f51\u7edc\u7f16\u7a0b\u2014\u4f7f\u7528UDP\u534f\u8baeAPI\u5b9e\u73b0\u56de\u663e\u670d\u52a1\u5668"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/10357","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=10357"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/10357\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/10350"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=10357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=10357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=10357"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=10357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}