|
|
@@ -106,10 +106,9 @@ namespace UAS_PLCDataReader.PublicMethod
|
|
|
IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
|
|
|
for (int i = 0; i < IpEntry.AddressList.Length; i++)
|
|
|
{
|
|
|
- if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
|
|
|
- {
|
|
|
- if (IpEntry.AddressList[i].ToString().Contains("192.168.127.20"))
|
|
|
- iP = IpEntry.AddressList[i].ToString();
|
|
|
+ if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork) {
|
|
|
+ if(IpEntry.AddressList[i].ToString().Contains("192.168.127.20"))
|
|
|
+ iP = IpEntry.AddressList[i].ToString();
|
|
|
}
|
|
|
}
|
|
|
//定义一个套接字用于监听客户端发来的信息 包含3个参数(IP4寻址协议,流式连接,TCP协议)
|
|
|
@@ -122,7 +121,7 @@ namespace UAS_PLCDataReader.PublicMethod
|
|
|
socketWatch.Bind(endpoint);
|
|
|
//将套接字的监听队列长度限制为20
|
|
|
socketWatch.Listen(20);
|
|
|
- Task.Factory.StartNew(WatchConnecting, TaskCreationOptions.LongRunning);
|
|
|
+ Task.Factory.StartNew(WatchConnecting,TaskCreationOptions.LongRunning);
|
|
|
////创建一个监听线程
|
|
|
//threadWatch = new Thread(WatchConnecting);
|
|
|
////将窗体线程设置为与后台同步
|
|
|
@@ -177,7 +176,7 @@ namespace UAS_PLCDataReader.PublicMethod
|
|
|
string hexOutput = String.Format("{0:X}", value);
|
|
|
strH += hexOutput + " ";
|
|
|
}
|
|
|
- item.Send(arr);
|
|
|
+ item.Send(Encoding.UTF8.GetBytes(strH));
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -251,7 +250,6 @@ namespace UAS_PLCDataReader.PublicMethod
|
|
|
//将接收到的信息存入到内存缓冲区,并返回其字节数组的长度
|
|
|
try
|
|
|
{
|
|
|
-
|
|
|
int length = socketServer.Receive(arrServerRecMsg);
|
|
|
if (length == 0)
|
|
|
{
|