private void SetNewConnection() { SharedData.ConnName = (string)this.listBoxConnName.Items[this.listBoxConnName.SelectedIndex]; SharedData.CurrentInterfaceIPAddress = (string)this.listBoxLocalAddr.Items[this.listBoxConnName.SelectedIndex]; SharedData.CurrentMulticastAddress = (string)this.listBoxIPAddress.Items[this.listBoxConnName.SelectedIndex]; SharedData.Current_Port = int.Parse((string)this.listBoxPort.Items[this.listBoxConnName.SelectedIndex]); if (ASTERIX.ReinitializeSocket() != true) { SharedData.ResetConnectionParameters(); } }
private void SetInputConnectionToReplayParameters() { bool Input_Validated = true; IPAddress IP = IPAddress.Any; IPAddress Multicast = IPAddress.Any; int PortNumber = 2222; // First make sure that all boxes are filled out if ((!string.IsNullOrEmpty(this.txtboxIPAddress.Text)) && (!string.IsNullOrEmpty(this.comboBoxNetworkInterface.Text)) && (!string.IsNullOrEmpty(this.textboxPort.Text))) { // Validate that a valid IP address is entered if ((IPAddress.TryParse(this.txtboxIPAddress.Text, out Multicast) != true) || (IPAddress.TryParse(this.comboBoxNetworkInterface.Text, out IP) != true)) { MessageBox.Show("Not a valid IP address"); Input_Validated = false; } else // Add a check that this is a valid multicast address { UdpClient TempSock; TempSock = new UdpClient(2222);// Port does not matter // Open up a new socket with the net IP address and port number try { TempSock.JoinMulticastGroup(Multicast, 50); // 50 is TTL value } catch { MessageBox.Show("Not valid Multicast address (has to be in range 224.0.0.0 to 239.255.255.255"); Input_Validated = false; } if (TempSock != null) { TempSock.Close(); } } if (int.TryParse(this.textboxPort.Text, out PortNumber) && (PortNumber >= 1 && PortNumber <= 65535)) { } else { MessageBox.Show("Invalid Port number"); Input_Validated = false; } } else { MessageBox.Show("Please fill out all data fileds"); Input_Validated = false; } // Input has been validated, so lets connect to the provided multicast address and interface if (Input_Validated == true) { // Syntatically all the provided data is valid, so save it off so it persists over the sessions Properties.Settings.Default.ReplayMulticast = this.txtboxIPAddress.Text; Properties.Settings.Default.ReplayPort = this.textboxPort.Text; Properties.Settings.Default.Save(); SharedData.ConnName = "Loc Replay"; SharedData.CurrentInterfaceIPAddress = this.comboBoxNetworkInterface.Text; SharedData.CurrentMulticastAddress = this.txtboxIPAddress.Text; SharedData.Current_Port = int.Parse(this.textboxPort.Text); if (ASTERIX.ReinitializeSocket() != true) { SharedData.ResetConnectionParameters(); } } }