diff --git a/Assets/MsgTransmitTools/ExtendLinkModel/UDPClient/Script/UDPClientView.cs b/Assets/MsgTransmitTools/ExtendLinkModel/UDPClient/Script/UDPClientView.cs index 8ee32f6..39ca840 100644 --- a/Assets/MsgTransmitTools/ExtendLinkModel/UDPClient/Script/UDPClientView.cs +++ b/Assets/MsgTransmitTools/ExtendLinkModel/UDPClient/Script/UDPClientView.cs @@ -62,13 +62,13 @@ namespace JXSoft { } public void sendMsg() { - this.GetUtility().sendData(InputSendMsg.text); + this.GetUtility().sendData(InputSendMsg.text,"192.168.1.41", 8443); } public void initUDPService() { UDPAddress = "192.168.1.41"; - UDPPort = 52101; + UDPPort = 20000; this.RegisterLinkStateEvent((int)UDPLinkState.Linking, () => { Debug.Log("UDP开始链接"); this.GetModel().linkServer(); diff --git a/Assets/MsgTransmitTools/ExtendLinkModel/UDPClient/Script/UDPUtility.cs b/Assets/MsgTransmitTools/ExtendLinkModel/UDPClient/Script/UDPUtility.cs index cd610f3..6fc9306 100644 --- a/Assets/MsgTransmitTools/ExtendLinkModel/UDPClient/Script/UDPUtility.cs +++ b/Assets/MsgTransmitTools/ExtendLinkModel/UDPClient/Script/UDPUtility.cs @@ -19,6 +19,7 @@ public class UDPUtility : IUtility public string exceptionData = ""; public Thread reciveT; public bool isTimeOut = false; + private IPEndPoint RemoteIpEndPoint; public UDPUtility() { @@ -41,7 +42,8 @@ public class UDPUtility : IUtility udpPort = port; try { - udpClient = new UdpClient(udpAddress, udpPort); + RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, udpPort); + udpClient = new UdpClient(RemoteIpEndPoint); } catch (Exception e) { @@ -71,6 +73,13 @@ public class UDPUtility : IUtility Byte[] sendBytes = Encoding.Default.GetBytes(data); udpClient.Send(sendBytes, sendBytes.Length); } + public void sendData(string data,string ip,int port) + { + if (isOpenUDP == false) + return; + Byte[] sendBytes = Encoding.Default.GetBytes(data); + udpClient.Send(sendBytes, sendBytes.Length,ip,port); + } public void RecciveMsg() { @@ -80,7 +89,6 @@ public class UDPUtility : IUtility { try { - IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0); Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint); msg = Encoding.UTF8.GetString(receiveBytes); if (msg != "")