| | |
| | | |
| | | public class TcpServer |
| | | { |
| | | public static Dictionary<string,string> TrayIps = new Dictionary<string,string>(); |
| | | public static Dictionary<string, string> TrayIps = new Dictionary<string, string>(); |
| | | public TcpServer(string ip) |
| | | { |
| | | Init(ip); |
| | |
| | | //} |
| | | //else |
| | | //{ |
| | | Console.WriteLine($"ãTCPä¿¡æ¯åè®®å¼å¸¸ {DateTime.Now.Millisecond}ãï¼IPï¼{remote_ip},MSGï¼{message}"); |
| | | Console.WriteLine($"ãTCPä¿¡æ¯åè®® {DateTime.Now.Millisecond}ãï¼IPï¼{remote_ip},MSGï¼{message}"); |
| | | var mg = Encoding.ASCII.GetString(PlcHelper.Hex2Bin(message)); |
| | | Console.WriteLine(mg); |
| | | if (mg.StartsWith("DK") && mg.Trim().Length == "DK01000024".Length) |
| | | if (mg.Length > 10) |
| | | { |
| | | if(TrayIps.TryGetValue(remote_ip,out string traycode)) |
| | | mg = mg.Substring(0, 10); |
| | | } |
| | | Console.WriteLine(mg); |
| | | if (mg.StartsWith("DK"))//&& mg.Trim().Length == "DK01000024".Length |
| | | { |
| | | LogHelper.Info($"æ«ç å¨ >{remote_ip} -{mg}"); |
| | | if (TrayIps.TryGetValue(remote_ip, out string traycode)) |
| | | { |
| | | TrayIps[remote_ip] = traycode; |
| | | }else TrayIps.Add(remote_ip, traycode); |
| | | Console.WriteLine("TOFF"); |
| | | var mst = PlcHelper.Hex2Bin("544F4646"); |
| | | TcpServer.TcpServerSend(remote_ip, mst); |
| | | TrayIps[remote_ip] = mg; |
| | | } |
| | | else TrayIps.Add(remote_ip, mg); |
| | | |
| | | //Console.WriteLine("TOFF"); |
| | | //var mst = PlcHelper.Hex2Bin("544F4646"); |
| | | //TcpServer.TcpServerSend(remote_ip, mst); |
| | | } |
| | | //} |
| | | } |
| | |
| | | |
| | | public static bool TcpServerSend(string ip, byte[] msg) |
| | | { |
| | | LogHelper.Info($"TcpServerSend >{ip}:{msg}"); |
| | | if (clients.Keys.Contains(ip)) |
| | | { |
| | | var client = clients[ip]; |
| | |
| | | try |
| | | { |
| | | client.Send(msg); |
| | | LogHelper.Info($"TcpServerSend > åéæåã"); |
| | | return true; |
| | | } |
| | | catch (SocketException ex) |
| | |
| | | // 转æ¢ååè¿å¶ |
| | | return Convert.ToInt32(new string(binaryChars), 2); |
| | | } |
| | | public static List<string> GetStaticClients() => clients.Keys.ToList(); |
| | | public static Dictionary<string, string> GetStaticScan() => TrayIps; |
| | | } |
| | | } |
| | | |