| | |
| | | } |
| | | private void Init(string ip, int port) |
| | | { |
| | | //创建一个新的Socket,这里我们使用最常用的基于TCP的Stream Socket(流式套接字) |
| | | //创建一个新的Socket,这里我们使用最常用的基于TCP的Stream Socket (流式套接字) |
| | | var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); |
| | | try |
| | | { |
| | | //将该socket绑定到主机上面的某个端口,端口应该放到配置文件中 |
| | | //将该socket绑定到主机上面的某个端口,端口应该放到配置文件中 |
| | | socket.Bind(new IPEndPoint(IPAddress.Parse(ip), port)); |
| | | Console.WriteLine(port); |
| | | //启动监听,并且设置一个最大的队列长度 |
| | | //启动监听,并且设置一个最大的队列长度 |
| | | socket.Listen(30); |
| | | //开始接受客户端连接请求 |
| | | socket.BeginAccept(new AsyncCallback(ClientAccepted), socket); |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine($"【接收客户端的消息异常】:" + ex.Message); |
| | | Console.WriteLine($"【接收客户端的消息异常】:" + ex.Message); |
| | | } |
| | | //准备接受下一个客户端请求 |
| | | socket.BeginAccept(new AsyncCallback(ClientAccepted), socket); |
| | |
| | | } |
| | | } |
| | | |
| | | //LogHelper.Info($"接收到信息,IP:{remote_ip},MSG:{BitConverter.ToString(buffers[remote_ip])}"); |
| | | //LogHelper.Info($"接收到信息,IP:{remote_ip},MSG:{BitConverter.ToString(buffers[remote_ip])}"); |
| | | |
| | | if (buffers.Keys.Contains(remote_ip)) |
| | | { |
| | |
| | | |
| | | string rfids16 = BitConverter.ToString(rfid); |
| | | string rfids = Encoding.ASCII.GetString(rfid); |
| | | //LogHelper.Info($"读卡器校验对应容器号:{rfids},其16进制形式:{rfids16}"); |
| | | //LogHelper.Info($"读卡器校验对应容器号:{rfids},其16进制形式:{rfids16}"); |
| | | //if (ScanCodeHelper.Analysis(remote_ip, rfids))//校验RFID |
| | | //{ |
| | | // isCheck[remote_ip] = false; |
| | |
| | | } |
| | | else |
| | | { |
| | | LogHelper.Info($"不满足读卡器校验规定:IP:{remote_ip},MSG:{message}"); |
| | | LogHelper.Info($"不满足读卡器校验规定:IP:{remote_ip},MSG:{message}"); |
| | | } |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | LogHelper.Info($"扫码校验发生了异常:{ex.Message}"); |
| | | LogHelper.Info($"扫码校验发生了异常:{ex.Message}"); |
| | | saoMa[remote_ip] = 4;//扫码异常 |
| | | } |
| | | |
| | |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | LogHelper.Info($"卷帘门校验发生了异常:{ex.Message}"); |
| | | LogHelper.Info($"卷帘门校验发生了异常:{ex.Message}"); |
| | | } |
| | | //TcpServerSend(remote_ip, System.Text.Encoding.Default.GetBytes(msgSend)); |
| | | Array.Clear(buffers[remote_ip], 0, buffers[remote_ip].Length);//清空当前IP Buffer |
| | |
| | | } |
| | | } |
| | | |
| | | //接收下一个消息(因为这是一个递归的调用,所以这样就可以一直接收消息了) |
| | | //接收下一个消息(因为这是一个递归的调用,所以这样就可以一直接收消息了) |
| | | socket.BeginReceive(buffers[remote_ip], 0, buffers[remote_ip].Length, SocketFlags.None, new AsyncCallback(ReceiveMessage), socket); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | LogHelper.InfoEx(ex); |
| | | } |
| | | } |
| | | |
| | |
| | | try |
| | | { |
| | | client.Send(msg); |
| | | LogHelper.Info($"已发送给该AGV地址{ip},{msg}"); |
| | | LogHelper.Info($"已发送给该AGV地址{ip},{msg}"); |
| | | return true; |
| | | } |
| | | catch (SocketException ex) |
| | |
| | | } |
| | | else |
| | | { |
| | | LogHelper.Info("未找到该设备,是否已连接?"); |
| | | LogHelper.Info("未找到该设备,是否已连接?"); |
| | | } |
| | | return false; |
| | | |