public clsRecieverSettings getReceiverSettings() { clsRecieverSettings rc = new clsRecieverSettings(); rc.allowedIp = txtRecieverIp.Text; rc.port = (UInt16)nutRecieverPort.Value; return(rc); }
private void bgwReciever_DoWork(object sender, DoWorkEventArgs e) { clsRecieverSettings rSettings = (clsRecieverSettings)e.Argument; try { UdpClient Server = new UdpClient(rSettings.port); IPEndPoint ClientEp = new IPEndPoint(IPAddress.Any, 0); while (!bgwReciever.CancellationPending) { byte[] ClientRequestData = Server.Receive(ref ClientEp); string ClientRequest = Encoding.ASCII.GetString(ClientRequestData); string senderIp = ClientEp.Address.ToString(); Console.WriteLine("Recived {0} from {1}, sending response", ClientRequest, senderIp); //Server.Send(ResponseData, ResponseData.Length, ClientEp); if (rSettings.allowedIp == "" || rSettings.allowedIp == senderIp) { string keystring = ClientRequest; if (keystring.Contains("|")) { Char delimiter = '|'; string[] parts = keystring.Split(delimiter); bgwReciever.ReportProgress(int.Parse(parts[1]), parts[0]); } } else { Console.WriteLine("BAD IP: " + senderIp); } } //e.Result = keystring; } catch (Exception ex) { Console.WriteLine(ex); } }