|
|
@ -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 != "") |
|
|
|