Browse Source

udp通讯调整,sscom助手测试通过

master
DESKTOP-B25GA9E\W35 2 years ago
parent
commit
26b8caaf33
  1. 4
      Assets/MsgTransmitTools/ExtendLinkModel/UDPClient/Script/UDPClientView.cs
  2. 12
      Assets/MsgTransmitTools/ExtendLinkModel/UDPClient/Script/UDPUtility.cs

4
Assets/MsgTransmitTools/ExtendLinkModel/UDPClient/Script/UDPClientView.cs

@ -62,13 +62,13 @@ namespace JXSoft {
} }
public void sendMsg() public void sendMsg()
{ {
this.GetUtility<UDPUtility>().sendData(InputSendMsg.text); this.GetUtility<UDPUtility>().sendData(InputSendMsg.text,"192.168.1.41", 8443);
} }
public void initUDPService() public void initUDPService()
{ {
UDPAddress = "192.168.1.41"; UDPAddress = "192.168.1.41";
UDPPort = 52101; UDPPort = 20000;
this.RegisterLinkStateEvent((int)UDPLinkState.Linking, () => { this.RegisterLinkStateEvent((int)UDPLinkState.Linking, () => {
Debug.Log("UDP开始链接"); Debug.Log("UDP开始链接");
this.GetModel<UDPClientModel>().linkServer(); this.GetModel<UDPClientModel>().linkServer();

12
Assets/MsgTransmitTools/ExtendLinkModel/UDPClient/Script/UDPUtility.cs

@ -19,6 +19,7 @@ public class UDPUtility : IUtility
public string exceptionData = ""; public string exceptionData = "";
public Thread reciveT; public Thread reciveT;
public bool isTimeOut = false; public bool isTimeOut = false;
private IPEndPoint RemoteIpEndPoint;
public UDPUtility() public UDPUtility()
{ {
@ -41,7 +42,8 @@ public class UDPUtility : IUtility
udpPort = port; udpPort = port;
try try
{ {
udpClient = new UdpClient(udpAddress, udpPort); RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, udpPort);
udpClient = new UdpClient(RemoteIpEndPoint);
} }
catch (Exception e) catch (Exception e)
{ {
@ -71,6 +73,13 @@ public class UDPUtility : IUtility
Byte[] sendBytes = Encoding.Default.GetBytes(data); Byte[] sendBytes = Encoding.Default.GetBytes(data);
udpClient.Send(sendBytes, sendBytes.Length); 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() public void RecciveMsg()
{ {
@ -80,7 +89,6 @@ public class UDPUtility : IUtility
{ {
try try
{ {
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint); Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
msg = Encoding.UTF8.GetString(receiveBytes); msg = Encoding.UTF8.GetString(receiveBytes);
if (msg != "") if (msg != "")

Loading…
Cancel
Save