private UdpCommunication GetUdpInstance() { if (_udp == null || !_udp.SendChanel.Client.IsBound) { _udp = new UdpCommunication(LocalPort, RemoteIp, RemotePort); } return(_udp); }
private INetworkCommunication GetNetworkCommunication() { var udpCom = new UdpCommunication(0); //return new DelayedNetworkCommunication(udpCom); return(udpCom); }
private void TestUDP_Load(object sender, EventArgs e) { dataTransmitter = new UdpCommunication(); string error; if (!dataTransmitter.Bind("127.0.0.1", out error)) { MessageBox.Show("绑定查询端口失败"); } }
/// <summary> /// 检测板重新标定指令下发 /// </summary> /// <param name="deviceNo">设备编号</param> /// <returns>SendCommandDto:是否下发成功及时间戳</returns> public async Task <SendCommandDto> ReCalibration(string deviceNo) { Task <SendCommandDto> taskDto = new Task <SendCommandDto>(() => { SendCommandDto dto = new SendCommandDto(); dto.IsSuccess = false; if (string.IsNullOrWhiteSpace(deviceNo)) { return(dto); } //查找设备是否存在且在线连接 var model = this._deviceInfo.GetAll().Where(d => d.DeviceNo == deviceNo && d.DeviceStatus == 1).FirstOrDefault(); if (model == null) { return(dto); } //查看设备绑定的IP地址 var iPmodel = this._deviceIPEndPort.GetAll().Where(p => p.IsUseing == true && p.DeviceNo == deviceNo).FirstOrDefault(); if (iPmodel == null || string.IsNullOrWhiteSpace(iPmodel.IpEndPort)) { return(dto); } IPAddress IPadr = IPAddress.Parse(iPmodel.IpEndPort.Split(':')[0]);//先把string类型转换成IPAddress类型 IPEndPoint ipEndPort = new IPEndPoint(IPadr, int.Parse(iPmodel.IpEndPort.Split(':')[1])); string timeStamp = DateTime.Now.ToString("yyyyMMddHHmmss"); string cmd = SendCommands.STestingBoardAgainSet(deviceNo, timeStamp); //插入数据记录帧 Command_Log cmdLog = new Command_Log { DeviceNo = deviceNo, CommandType = "A6", Tstamp = timeStamp, AddTime = DateTime.Now, SendType = 0, CmdStatus = 0 }; _commandLog.InsertAsync(cmdLog); //指令下发 bool ret = UdpCommunication.UpdSendMessage(cmd, ipEndPort); if (ret) { cmdLog.CmdStatus = 1; _commandLog.InsertOrUpdateAsync(cmdLog); dto.IsSuccess = true; dto.TimeStamp = timeStamp; } return(dto); }); taskDto.Start(); return(await taskDto); }
private INetworkCommunication GetNetworkCommunication() { var fakeClientsGO = GameObject.Find("FakeClients"); if (fakeClientsGO == null || !fakeClientsGO.activeSelf) { var udpCom = new UdpCommunication(GameSettings.ServerDefaultPort); return(new DelayedNetworkCommunication(udpCom)); } var fakeClients = fakeClientsGO.GetComponent <FakeClients>(); return(fakeClients.NetworkCommunication); }
private INetworkCommunication GetNetworkCommunication() { var fakeServerGO = GameObject.Find("FakeServer"); if (fakeServerGO == null || !fakeServerGO.activeSelf) { var udpCom = new UdpCommunication(0); return(new DelayedNetworkCommunication(udpCom)); } var fakeServer = fakeServerGO.GetComponent <FakeServer>(); return(fakeServer.NetworkCommunication); }
private static void RunDesignPattern_Adapter() { Console.WriteLine("Start (7) Run Design Pattern - Adapter"); var description = "Adapter(轉接器模式)" + "\n" + "目的:將兩個以上不同的介面統一成一個介面,讓User更輕鬆維護。" + "\n" + "實際情境中,可能出現架構上已經設計兩套Library在專案中,突然需求需要第三個Library,這時候Adapter模式下只需要將共用介面引用至第三個Library中開發完交付給User,User只有修改new出第三套Libraray所產生的Instance就大功告成了。"; Console.WriteLine(description); Console.WriteLine("------------------------------------------------------------------------"); // Example 1 //Lib_1 ICommunication Tunnel = new UdpCommunication(); //Lib_2 //ICommunication Tunnel = new TcpCommunication(); //Lib_3 //ICommunication Tunnel = new MqttCommunication(); try { Tunnel.Connect("192.168.243.1", 3254); byte[] sendBuffer = GetSendBuffer(); Tunnel.Send(sendBuffer); byte[] receiveBuffer = Tunnel.Receive(); Tunnel.Disconnect(); Console.WriteLine(GetReceiveString(receiveBuffer)); } catch (Exception e) { Console.WriteLine(e.ToString()); } // Example 2 var a = new Adapter1(); a.Main(); Console.WriteLine("Done. 請按任意鍵繼續"); Console.ReadLine(); }
public InstrumentOperation(int localPort, string remoteIp, int remotePort) { Communication = new UdpCommunication(localPort, remoteIp, remotePort); }