|
|
@@ -84,6 +84,8 @@ namespace UAS_DeviceMonitor.PublicMethod
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public Dictionary<string, string> ReceiveCoding = new Dictionary<string, string>();
|
|
|
+
|
|
|
private string iP;
|
|
|
|
|
|
private string port;
|
|
|
@@ -106,7 +108,6 @@ namespace UAS_DeviceMonitor.PublicMethod
|
|
|
if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
|
|
|
iP = IpEntry.AddressList[i].ToString();
|
|
|
}
|
|
|
- Console.WriteLine(iP);
|
|
|
//定义一个套接字用于监听客户端发来的信息 包含3个参数(IP4寻址协议,流式连接,TCP协议)
|
|
|
socketWatch = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
|
|
//服务端发送信息 需要1个IP地址和端口号
|
|
|
@@ -133,8 +134,10 @@ namespace UAS_DeviceMonitor.PublicMethod
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void Send(string IPAddress, string EnCoding, string Command)
|
|
|
+ public void Send(string IPAddress, string EnCoding, string receiveCoding, string Command)
|
|
|
{
|
|
|
+ if (!ReceiveCoding.ContainsKey(IPAddress))
|
|
|
+ ReceiveCoding.Add(IPAddress, receiveCoding);
|
|
|
foreach (Socket item in list)
|
|
|
{
|
|
|
if (item != null)
|
|
|
@@ -226,13 +229,6 @@ namespace UAS_DeviceMonitor.PublicMethod
|
|
|
thread.IsBackground = true;
|
|
|
//启动线程
|
|
|
thread.Start(connection);
|
|
|
- //创建一个通信线程
|
|
|
- //ParameterizedThreadStart sed = new ParameterizedThreadStart(sends);
|
|
|
- //Thread threadsed = new Thread(sed);
|
|
|
- //设置为后台线程,随着主线程退出而退出
|
|
|
- //threadsed.IsBackground = true;
|
|
|
- //启动线程
|
|
|
- //threadsed.Start(connection);
|
|
|
list.Add(connection);
|
|
|
}
|
|
|
}
|
|
|
@@ -253,10 +249,26 @@ namespace UAS_DeviceMonitor.PublicMethod
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
- if (!returnvalue.ContainsKey(socketServer.RemoteEndPoint.ToString()))
|
|
|
- returnvalue.Add(socketServer.RemoteEndPoint.ToString(), Encoding.UTF8.GetString(arrServerRecMsg, 0, length));
|
|
|
- //将机器接受到的字节数组转换为人可以读懂的字符串
|
|
|
- //将发送的字符串信息附加到文本框txtMsg上
|
|
|
+ if (ReceiveCoding.ContainsKey(socketServer.RemoteEndPoint.ToString()))
|
|
|
+ {
|
|
|
+ if (!returnvalue.ContainsKey(socketServer.RemoteEndPoint.ToString()))
|
|
|
+ {
|
|
|
+ switch (ReceiveCoding[socketServer.RemoteEndPoint.ToString()])
|
|
|
+ {
|
|
|
+ case "UTF-8":
|
|
|
+ returnvalue.Add(socketServer.RemoteEndPoint.ToString(), Encoding.UTF8.GetString(arrServerRecMsg, 0, length));
|
|
|
+ break;
|
|
|
+ case "ASCII":
|
|
|
+ returnvalue.Add(socketServer.RemoteEndPoint.ToString(), Encoding.ASCII.GetString(arrServerRecMsg, 0, length));
|
|
|
+ break;
|
|
|
+ case "Hexadecimal":
|
|
|
+ returnvalue.Add(socketServer.RemoteEndPoint.ToString(), BaseUtil.ByteToHexadecimalString(arrServerRecMsg, length));
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|