{"id":11689,"date":"2025-04-18T18:55:03","date_gmt":"2025-04-18T10:55:03","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/11689.html"},"modified":"2025-04-18T18:55:03","modified_gmt":"2025-04-18T10:55:03","slug":"%e5%ae%9e%e7%8e%b0%e5%ae%a2%e6%88%b7%e7%ab%af%e4%b8%8e%e6%9c%8d%e5%8a%a1%e5%99%a8%e9%97%b4%e7%ae%80%e6%98%93%e7%9a%84udp%e5%90%8c%e6%ad%a5%e9%80%9a%e4%bf%a1","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/11689.html","title":{"rendered":"\u5b9e\u73b0\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u95f4\u7b80\u6613\u7684UDP\u540c\u6b65\u901a\u4fe1"},"content":{"rendered":"<h3>\u4ec0\u4e48\u662fUDP\u901a\u4fe1<\/h3>\n<p>UDP&#xff08;User Datagram Protocol&#xff0c;\u7528\u6237\u6570\u636e\u62a5\u534f\u8bae&#xff09;\u901a\u4fe1\u662f\u4e00\u79cd\u5728\u8ba1\u7b97\u673a\u7f51\u7edc\u4e2d\u4f7f\u7528\u7684\u4f20\u8f93\u5c42\u901a\u4fe1\u534f\u8bae&#xff0c;\u4ee5\u4e0b\u662f\u5173\u4e8e\u5b83\u7684\u8be6\u7ec6\u4ecb\u7ecd&#xff1a;<\/p>\n<ul>\n<li>\u57fa\u672c\u6982\u5ff5&#xff1a;UDP \u662f\u4e00\u79cd\u65e0\u8fde\u63a5\u7684\u534f\u8bae&#xff0c;\u5b83\u5728\u6570\u636e\u4f20\u8f93\u65f6\u4e0d\u9700\u8981\u5148\u5efa\u7acb\u8fde\u63a5&#xff0c;\u5c31\u53ef\u4ee5\u76f4\u63a5\u5c06\u6570\u636e\u62a5\u53d1\u9001\u5230\u76ee\u6807\u5730\u5740\u3002\u8fd9\u5c31\u597d\u6bd4\u5199\u4fe1&#xff0c;\u4f60\u4e0d\u9700\u8981\u4e8b\u5148\u901a\u77e5\u5bf9\u65b9\u5c31\u53ef\u4ee5\u76f4\u63a5\u628a\u4fe1\u5bc4\u51fa\u53bb&#xff0c;\u5bf9\u65b9\u6536\u5230\u4fe1\u540e\u4e5f\u4e0d\u4f1a\u7ed9\u4f60\u53d1\u9001\u786e\u8ba4\u6536\u5230\u7684\u6d88\u606f\u3002<\/li>\n<li>\u5de5\u4f5c\u539f\u7406&#xff1a;UDP \u901a\u4fe1\u4e2d&#xff0c;\u53d1\u9001\u65b9\u5c06\u6570\u636e\u5c01\u88c5\u6210 UDP \u6570\u636e\u5305&#xff0c;\u6bcf\u4e2a\u6570\u636e\u5305\u5305\u542b\u6e90\u7aef\u53e3\u53f7\u3001\u76ee\u7684\u7aef\u53e3\u53f7\u3001\u6570\u636e\u957f\u5ea6\u548c\u6570\u636e\u7b49\u4fe1\u606f\u3002\u7136\u540e&#xff0c;\u8fd9\u4e9b\u6570\u636e\u5305\u901a\u8fc7\u7f51\u7edc\u4f20\u8f93\u5230\u63a5\u6536\u65b9\u3002\u63a5\u6536\u65b9\u6839\u636e\u76ee\u7684\u7aef\u53e3\u53f7\u6765\u63a5\u6536\u548c\u5904\u7406\u6570\u636e\u3002\u7531\u4e8e UDP \u6ca1\u6709\u5efa\u7acb\u8fde\u63a5\u7684\u8fc7\u7a0b&#xff0c;\u4e5f\u6ca1\u6709\u786e\u8ba4\u673a\u5236&#xff0c;\u6240\u4ee5\u5b83\u4e0d\u4fdd\u8bc1\u6570\u636e\u4e00\u5b9a\u80fd\u51c6\u786e\u65e0\u8bef\u5730\u5230\u8fbe\u63a5\u6536\u65b9&#xff0c;\u4e5f\u4e0d\u4fdd\u8bc1\u6570\u636e\u7684\u63a5\u6536\u987a\u5e8f\u548c\u53d1\u9001\u987a\u5e8f\u4e00\u81f4\u3002<\/li>\n<li>\u7279\u70b9\n<ul>\n<li>\u7b80\u5355\u9ad8\u6548&#xff1a;\u56e0\u4e3a\u4e0d\u9700\u8981\u5efa\u7acb\u548c\u7ef4\u62a4\u8fde\u63a5&#xff0c;\u6240\u4ee5 UDP \u7684\u5f00\u9500\u5c0f&#xff0c;\u4f20\u8f93\u901f\u5ea6\u5feb&#xff0c;\u9002\u5408\u5bf9\u5b9e\u65f6\u6027\u8981\u6c42\u9ad8\u7684\u5e94\u7528&#xff0c;\u5982\u89c6\u9891\u76f4\u64ad\u3001\u97f3\u9891\u901a\u8bdd\u7b49\u3002\u5728\u8fd9\u4e9b\u5e94\u7528\u4e2d&#xff0c;\u5076\u5c14\u4e22\u5931\u4e00\u4e9b\u6570\u636e\u5bf9\u6574\u4f53\u7684\u89c2\u770b\u6216\u6536\u542c\u4f53\u9a8c\u5f71\u54cd\u4e0d\u5927&#xff0c;\u4f46\u5982\u679c\u56e0\u4e3a\u5efa\u7acb\u8fde\u63a5\u7b49\u64cd\u4f5c\u5bfc\u81f4\u5ef6\u8fdf\u8fc7\u9ad8&#xff0c;\u5c31\u4f1a\u4e25\u91cd\u5f71\u54cd\u7528\u6237\u4f53\u9a8c\u3002<\/li>\n<li>\u65e0\u8fde\u63a5\u6027&#xff1a;\u53d1\u9001\u65b9\u53ef\u4ee5\u968f\u65f6\u5411\u63a5\u6536\u65b9\u53d1\u9001\u6570\u636e&#xff0c;\u4e0d\u53d7\u8fde\u63a5\u72b6\u6001\u7684\u9650\u5236&#xff0c;\u6bd4\u8f83\u7075\u6d3b\u3002<\/li>\n<li>\u4e0d\u53ef\u9760\u6027&#xff1a;UDP \u4e0d\u63d0\u4f9b\u6570\u636e\u7684\u53ef\u9760\u6027\u4f20\u8f93&#xff0c;\u53ef\u80fd\u4f1a\u51fa\u73b0\u6570\u636e\u4e22\u5931\u3001\u91cd\u590d\u6216\u4e71\u5e8f\u7684\u60c5\u51b5\u3002\u4f8b\u5982&#xff0c;\u5728\u7f51\u7edc\u62e5\u585e\u65f6&#xff0c;\u6570\u636e\u5305\u53ef\u80fd\u4f1a\u88ab\u4e22\u5f03\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5e94\u7528\u573a\u666f\n<ul>\n<li>\u5b9e\u65f6\u97f3\u89c6\u9891\u4f20\u8f93&#xff1a;\u5982\u89c6\u9891\u4f1a\u8bae\u3001\u5728\u7ebf\u6e38\u620f\u7b49\u3002\u5728\u8fd9\u4e9b\u573a\u666f\u4e2d&#xff0c;\u6570\u636e\u7684\u5b9e\u65f6\u6027\u81f3\u5173\u91cd\u8981&#xff0c;\u5c11\u91cf\u7684\u6570\u636e\u4e22\u5931\u53ef\u4ee5\u63a5\u53d7&#xff0c;\u56e0\u4e3a\u91cd\u65b0\u4f20\u8f93\u53ef\u80fd\u4f1a\u5bfc\u81f4\u66f4\u5927\u7684\u5ef6\u8fdf&#xff0c;\u5f71\u54cd\u7528\u6237\u4f53\u9a8c\u3002<\/li>\n<li>\u57df\u540d\u7cfb\u7edf&#xff08;DNS&#xff09;&#xff1a;DNS \u7528\u4e8e\u5c06\u57df\u540d\u8f6c\u6362\u4e3a IP \u5730\u5740&#xff0c;\u901a\u5e38\u4f7f\u7528 UDP \u534f\u8bae\u8fdb\u884c\u67e5\u8be2\u548c\u54cd\u5e94\u3002\u56e0\u4e3a DNS \u67e5\u8be2\u901a\u5e38\u6bd4\u8f83\u7b80\u5355&#xff0c;\u800c\u4e14\u5bf9\u901f\u5ea6\u8981\u6c42\u8f83\u9ad8&#xff0c;UDP \u7684\u5feb\u901f\u4f20\u8f93\u7279\u6027\u80fd\u591f\u6ee1\u8db3\u5176\u9700\u6c42\u3002<\/li>\n<li>\u7b80\u5355\u7f51\u7edc\u7ba1\u7406\u534f\u8bae&#xff08;SNMP&#xff09;&#xff1a;\u7528\u4e8e\u7ba1\u7406\u548c\u76d1\u63a7\u7f51\u7edc\u8bbe\u5907\u3002SNMP \u4ee3\u7406\u4f7f\u7528 UDP \u5c06\u8bbe\u5907\u4fe1\u606f\u53d1\u9001\u7ed9\u7ba1\u7406\u7ad9&#xff0c;\u7531\u4e8e\u5bf9\u5b9e\u65f6\u6027\u6709\u4e00\u5b9a\u8981\u6c42&#xff0c;\u4e14\u6570\u636e\u91cf\u901a\u5e38\u4e0d\u5927&#xff0c;UDP \u662f\u5408\u9002\u7684\u9009\u62e9\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3 style=\"background-color:transparent\">UDP\u548cTCP\u901a\u8baf\u7684\u533a\u522b<\/h3>\n<p>UDP \u548c TCP \u662f\u4e24\u79cd\u5e38\u7528\u7684\u4f20\u8f93\u5c42\u534f\u8bae&#xff0c;\u5b83\u4eec\u7684\u8bbe\u8ba1\u76ee\u6807\u548c\u7279\u6027\u6709\u663e\u8457\u5dee\u5f02&#xff0c;\u4ee5\u4e0b\u662f\u5177\u4f53\u5bf9\u6bd4&#xff1a;<\/p>\n<h4>1. \u8fde\u63a5\u6027<\/h4>\n<ul>\n<li>\n<p>UDP&#xff08;\u65e0\u8fde\u63a5&#xff09; \u65e0\u9700\u5efa\u7acb\u8fde\u63a5\u5373\u53ef\u76f4\u63a5\u53d1\u9001\u6570\u636e&#xff0c;\u7c7b\u4f3c \u201c\u5199\u4fe1\u201d&#xff1a; \u53d1\u9001\u65b9\u76f4\u63a5\u5c06\u6570\u636e\u5305&#xff08;\u6570\u636e\u62a5&#xff09;\u53d1\u5f80\u63a5\u6536\u65b9&#xff0c;\u4e0d\u5173\u5fc3\u5bf9\u65b9\u662f\u5426\u5728\u7ebf\u6216\u80fd\u5426\u63a5\u6536\u3002 \u5178\u578b\u573a\u666f&#xff1a;DNS \u67e5\u8be2\u3001\u89c6\u9891\u76f4\u64ad\u3002<\/p>\n<\/li>\n<li>\n<p>TCP&#xff08;\u9762\u5411\u8fde\u63a5&#xff09; \u5fc5\u987b\u5148\u5efa\u7acb\u8fde\u63a5&#xff08;\u4e09\u6b21\u63e1\u624b&#xff09;&#xff0c;\u7c7b\u4f3c \u201c\u6253\u7535\u8bdd\u201d&#xff1a; \u53d1\u9001\u65b9\u548c\u63a5\u6536\u65b9\u9700\u786e\u8ba4\u8fde\u63a5\u72b6\u6001\u540e\u624d\u4f20\u8f93\u6570\u636e&#xff0c;\u786e\u4fdd\u901a\u4fe1\u53cc\u65b9\u5c31\u7eea\u3002 \u5178\u578b\u573a\u666f&#xff1a;\u7f51\u9875\u6d4f\u89c8&#xff08;HTTP&#xff09;\u3001\u6587\u4ef6\u4f20\u8f93&#xff08;FTP&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>2. \u53ef\u9760\u6027<\/h4>\n<ul>\n<li>\n<p>UDP&#xff08;\u4e0d\u53ef\u9760&#xff09;<\/p>\n<ul>\n<li>\u4e0d\u4fdd\u8bc1\u6570\u636e\u9001\u8fbe\u3001\u4e0d\u91cd\u590d\u3001\u4e0d\u4e22\u5305\u3001\u6309\u5e8f\u5230\u8fbe\u3002<\/li>\n<li>\u82e5\u6570\u636e\u4e22\u5931\u6216\u4e71\u5e8f&#xff0c;\u4e0d\u91cd\u4f20\u3001\u4e0d\u6392\u5e8f\u3002 \u9002\u7528\u573a\u666f&#xff1a;\u5bf9\u5b9e\u65f6\u6027\u8981\u6c42\u9ad8&#xff08;\u5982\u6e38\u620f\u3001\u8bed\u97f3\u901a\u8bdd&#xff09;&#xff0c;\u5c11\u91cf\u4e22\u5305\u53ef\u63a5\u53d7\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>TCP&#xff08;\u53ef\u9760&#xff09;<\/p>\n<ul>\n<li>\u901a\u8fc7\u786e\u8ba4\u673a\u5236&#xff08;ACK&#xff09;\u3001\u91cd\u4f20\u673a\u5236&#xff08;\u8d85\u65f6\u91cd\u4f20&#xff09;\u3001\u5e8f\u5217\u53f7\u4fdd\u8bc1\u6570\u636e\u5b8c\u6574\u4e14\u6309\u5e8f\u5230\u8fbe\u3002<\/li>\n<li>\u82e5\u6570\u636e\u4e22\u5931\u6216\u4e71\u5e8f&#xff0c;\u81ea\u52a8\u91cd\u4f20\u5e76\u6392\u5e8f\u3002 \u9002\u7528\u573a\u666f&#xff1a;\u5bf9\u6570\u636e\u5b8c\u6574\u6027\u8981\u6c42\u9ad8&#xff08;\u5982\u6587\u4ef6\u4e0b\u8f7d\u3001\u94f6\u884c\u4ea4\u6613&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>3. \u4f20\u8f93\u6548\u7387\u4e0e\u5f00\u9500<\/h4>\n<ul>\n<li>\n<p>UDP<\/p>\n<ul>\n<li>\u9996\u90e8\u5f00\u9500\u5c0f&#xff08;\u4ec5 8 \u5b57\u8282&#xff09;&#xff0c;\u65e0\u8fde\u63a5\u5efa\u7acb\u548c\u7ef4\u62a4\u6210\u672c\u3002<\/li>\n<li>\u4f20\u8f93\u901f\u5ea6\u5feb&#xff0c;\u9002\u5408\u5c0f\u6570\u636e\u91cf\u3001\u4f4e\u5ef6\u8fdf\u573a\u666f\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>TCP<\/p>\n<ul>\n<li>\u9996\u90e8\u5f00\u9500\u5927&#xff08;\u81f3\u5c11 20 \u5b57\u8282&#xff09;&#xff0c;\u9700\u7ef4\u62a4\u8fde\u63a5\u72b6\u6001&#xff08;\u5982\u5e8f\u5217\u53f7\u3001\u786e\u8ba4\u53f7&#xff09;\u3002<\/li>\n<li>\u5305\u542b\u62e5\u585e\u63a7\u5236\u673a\u5236&#xff08;\u907f\u514d\u7f51\u7edc\u62e5\u5835&#xff09;&#xff0c;\u53ef\u80fd\u56e0\u91cd\u4f20\u5bfc\u81f4\u5ef6\u8fdf\u3002 \u6ce8&#xff1a;TCP \u7684\u53ef\u9760\u6027\u662f\u4ee5\u727a\u7272\u901f\u5ea6\u548c\u5e26\u5bbd\u4e3a\u4ee3\u4ef7\u7684\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>4. \u4f20\u8f93\u6a21\u5f0f<\/h4>\n<ul>\n<li>\n<p>UDP&#xff08;\u6570\u636e\u62a5&#xff09;<\/p>\n<ul>\n<li>\u6570\u636e\u4ee5\u72ec\u7acb\u6570\u636e\u5305\u4f20\u8f93&#xff0c;\u8fb9\u754c\u6e05\u6670&#xff08;\u53d1\u9001\u65b9\u53d1\u4e00\u4e2a\u5305&#xff0c;\u63a5\u6536\u65b9\u6536\u4e00\u4e2a\u5305&#xff09;\u3002<\/li>\n<li>\u793a\u4f8b&#xff1a;\u53d1\u9001 \u201cABC\u201d \u548c \u201cDEF\u201d&#xff0c;\u63a5\u6536\u65b9\u53ef\u80fd\u6536\u5230\u4e24\u4e2a\u72ec\u7acb\u6570\u636e\u5305\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>TCP&#xff08;\u5b57\u8282\u6d41&#xff09;<\/p>\n<ul>\n<li>\u6570\u636e\u4ee5\u8fde\u7eed\u5b57\u8282\u6d41\u4f20\u8f93&#xff0c;\u65e0\u8fb9\u754c\u6982\u5ff5&#xff08;\u53d1\u9001\u65b9\u5206\u591a\u6b21\u53d1\u9001&#xff0c;\u63a5\u6536\u65b9\u53ef\u80fd\u4e00\u6b21\u6027\u8bfb\u53d6&#xff09;\u3002<\/li>\n<li>\u793a\u4f8b&#xff1a;\u53d1\u9001 \u201cABC\u201d \u548c \u201cDEF\u201d&#xff0c;\u63a5\u6536\u65b9\u53ef\u80fd\u6536\u5230 \u201cABCDEF\u201d \u4e00\u4e2a\u6574\u4f53\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p style=\"text-align:center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"347\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418105502-68022f861c6e6.png\" width=\"547\" \/><\/p>\n<h3 style=\"background-color:transparent\">\u7528Unity\u505a\u5ba2\u6237\u7aef\u5b9e\u73b0UDP\u540c\u6b65\u901a\u4fe1\u903b\u8f91<\/h3>\n<p>\u64b0\u5199C#\u811a\u672c<\/p>\n<p>using System.Collections;<br \/>\nusing System.Collections.Generic;<br \/>\nusing System.Net;<br \/>\nusing System.Net.Sockets;<br \/>\nusing System.Text;<br \/>\nusing UnityEngine;<\/p>\n<p>public class Lesson14 : MonoBehaviour<br \/>\n{<br \/>\n    \/\/ Start is called before the first frame update<br \/>\n    void Start()<br \/>\n    {<br \/>\n        #region \u5b9e\u73b0UDP\u5ba2\u6237\u7aef\u901a\u4fe1 \u6536\u53d1\u5b57\u7b26\u4e32<br \/>\n        \/\/1.\u521b\u5efa\u5957\u63a5\u5b57<br \/>\n        Socket socket &#061; new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);<br \/>\n        \/\/2.\u7ed1\u5b9a\u672c\u673a\u5730\u5740<br \/>\n        IPEndPoint ipPoint &#061; new IPEndPoint(IPAddress.Parse(&#034;127.0.0.1&#034;), 8080);<br \/>\n        socket.Bind(ipPoint);<br \/>\n        \/\/3.\u53d1\u9001\u5230\u6307\u5b9a\u76ee\u6807<br \/>\n        IPEndPoint remoateIp &#061; new IPEndPoint(IPAddress.Parse(&#034;127.0.0.1&#034;),8081);<br \/>\n        \/\/\u6307\u5b9a\u8981\u53d1\u9001\u7684\u5b57\u8282\u6570\u548c\u8fdc\u7a0b\u8ba1\u7b97\u673a\u7684IP\u548c\u7aef\u53e3<br \/>\n        socket.SendTo(Encoding.UTF8 .GetBytes (&#034;\u6211\u662f\u5ba2\u6237\u7aef&#xff0c;\u4f60\u597d&#034;), remoateIp);<br \/>\n        \/\/4.\u63a5\u6536\u6d88\u606f<br \/>\n        byte[] bytes &#061; new byte[512];<br \/>\n        \/\/\u8fd9\u4e2a\u53d8\u91cf\u4e3b\u8981\u662f\u7528\u6765\u8bb0\u5f55 \u8c01\u53d1\u7684\u6d88\u606f\u7ed9\u4f60 \u4f20\u5165\u51fd\u6570\u540e \u5728\u5185\u90e8 \u5b83\u4f1a\u5e2e\u52a9\u6211\u4eec\u8fdb\u884c\u8d4b\u503c<br \/>\n        EndPoint remoateIp2 &#061; new IPEndPoint(IPAddress.Any, 0);<br \/>\n        int length&#061; socket.ReceiveFrom(bytes, ref remoateIp2);<br \/>\n        print(&#034;IP:&#034;&#043;(remoateIp2 as IPEndPoint).Address .ToString()<br \/>\n            &#043;&#034;Port:&#034;&#043;(remoateIp2 as IPEndPoint).Port<br \/>\n            &#043;&#034;\u53d1\u6765\u4e86:&#034;&#043;Encoding.UTF8.GetString(bytes, 0, length));<br \/>\n        \/\/5.\u91ca\u653e\u5173\u95ed<br \/>\n        socket.Shutdown(SocketShutdown.Both);<br \/>\n        socket.Close();<br \/>\n        #endregion<br \/>\n    }<\/p>\n<p>    \/\/ Update is called once per frame<br \/>\n    void Update()<br \/>\n    {<\/p>\n<p>    }<br \/>\n}<\/p>\n<h3>\u7528\u672c\u5730\u505a\u670d\u52a1\u5668\u5b9e\u73b0UDP\u540c\u6b65\u901a\u4fe1\u903b\u8f91<\/h3>\n<p>using System;<br \/>\nusing System.Collections.Generic;<br \/>\nusing System.Linq;<br \/>\nusing System.Net;<br \/>\nusing System.Net.Sockets;<br \/>\nusing System.Text;<br \/>\nusing System.Threading.Tasks;<\/p>\n<p>namespace UDPServer<br \/>\n{<br \/>\n    class Program<br \/>\n    {<br \/>\n        static void Main(string[] args)<br \/>\n        {<br \/>\n            #region \u5b9e\u73b0UDP\u670d\u52a1\u7aef\u901a\u4fe1\u6536\u53d1\u5b57\u7b26\u4e32<br \/>\n            \/\/1.\u521b\u5efa\u5957\u63a5\u5b57<br \/>\n            Socket socket &#061; new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);<br \/>\n            \/\/2.\u7ed1\u5b9a\u672c\u673a\u5730\u5740<br \/>\n            IPEndPoint ipPoint &#061; new IPEndPoint(IPAddress.Parse(&#034;127.0.0.1&#034;), 8081);<br \/>\n            socket.Bind(ipPoint);<br \/>\n            Console.WriteLine(&#034;\u670d\u52a1\u5668\u5f00\u542f\u6210\u529f&#034;);<br \/>\n            \/\/3.\u63a5\u6536\u6d88\u606f<br \/>\n            byte[] bytes &#061; new byte[512];<br \/>\n            EndPoint remoateIp2 &#061; new IPEndPoint(IPAddress.Any, 0);<br \/>\n            int length &#061; socket.ReceiveFrom(bytes, ref remoateIp2);<br \/>\n            Console .WriteLine(&#034;IP:&#034; &#043; (remoateIp2 as IPEndPoint).Address.ToString()<br \/>\n                &#043; &#034;Port:&#034; &#043; (remoateIp2 as IPEndPoint).Port<br \/>\n                &#043; &#034;\u53d1\u6765\u4e86:&#034; &#043; Encoding.UTF8.GetString(bytes, 0, length));<br \/>\n            \/\/4.\u53d1\u9001\u5230\u6307\u5b9a\u5730\u5740<br \/>\n            socket.SendTo(Encoding.UTF8.GetBytes(&#034;\u6b22\u8fce\u7ed9\u670d\u52a1\u5668\u53d1\u6d88\u606f&#034;), remoateIp2);<br \/>\n            \/\/5.\u91ca\u653e\u5173\u95ed<br \/>\n            socket.Shutdown(SocketShutdown.Both);<br \/>\n            socket.Close();<br \/>\n            #endregion<br \/>\n            Console.ReadKey();<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<h3>\u5b9e\u73b0\u7ed3\u679c<\/h3>\n<p>\u5c06\u811a\u672c\u6302\u8f7d\u5230Unity\u573a\u666f\u4e2d&#xff0c;\u8fd0\u884c\u670d\u52a1\u5668&#xff0c;\u6210\u529f\u5b9e\u73b0\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668UDP\u540c\u6b65\u901a\u4fe1<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418105502-68022f8646eb4.png\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.6k\u6b21\uff0c\u70b9\u8d5e41\u6b21\uff0c\u6536\u85cf18\u6b21\u3002\u7528C#\u5b9e\u73b0\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u4e4b\u95f4\u7684UDP\u540c\u6b65\u901a\u4fe1_unity udp \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u901a\u4fe1<\/p>\n","protected":false},"author":2,"featured_media":11687,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[193,183,599,43,78,191],"topic":[],"class_list":{"0":"post-11689","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","6":"hentry","7":"category-server","8":"tag-udp","9":"tag-unity","11":"tag-43","12":"tag-78","13":"tag-191"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5b9e\u73b0\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u95f4\u7b80\u6613\u7684UDP\u540c\u6b65\u901a\u4fe1 - \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\/11689.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5b9e\u73b0\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u95f4\u7b80\u6613\u7684UDP\u540c\u6b65\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.6k\u6b21\uff0c\u70b9\u8d5e41\u6b21\uff0c\u6536\u85cf18\u6b21\u3002\u7528C#\u5b9e\u73b0\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u4e4b\u95f4\u7684UDP\u540c\u6b65\u901a\u4fe1_unity udp \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u901a\u4fe1\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/11689.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-18T10:55:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418105502-68022f861c6e6.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/11689.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/11689.html\",\"name\":\"\u5b9e\u73b0\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u95f4\u7b80\u6613\u7684UDP\u540c\u6b65\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T10:55:03+00:00\",\"dateModified\":\"2025-04-18T10:55:03+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/11689.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/11689.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/11689.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5b9e\u73b0\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u95f4\u7b80\u6613\u7684UDP\u540c\u6b65\u901a\u4fe1\"}]},{\"@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":"\u5b9e\u73b0\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u95f4\u7b80\u6613\u7684UDP\u540c\u6b65\u901a\u4fe1 - \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\/11689.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5b9e\u73b0\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u95f4\u7b80\u6613\u7684UDP\u540c\u6b65\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.6k\u6b21\uff0c\u70b9\u8d5e41\u6b21\uff0c\u6536\u85cf18\u6b21\u3002\u7528C#\u5b9e\u73b0\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u4e4b\u95f4\u7684UDP\u540c\u6b65\u901a\u4fe1_unity udp \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u901a\u4fe1","og_url":"https:\/\/www.wsisp.com\/helps\/11689.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T10:55:03+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418105502-68022f861c6e6.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/11689.html","url":"https:\/\/www.wsisp.com\/helps\/11689.html","name":"\u5b9e\u73b0\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u95f4\u7b80\u6613\u7684UDP\u540c\u6b65\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T10:55:03+00:00","dateModified":"2025-04-18T10:55:03+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/11689.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/11689.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/11689.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5b9e\u73b0\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u95f4\u7b80\u6613\u7684UDP\u540c\u6b65\u901a\u4fe1"}]},{"@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\/11689","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=11689"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/11689\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/11687"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=11689"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=11689"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=11689"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=11689"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}