AsterixDisplayAnalyser.RecForwConnection1.StartForward C# (CSharp) Метод

StartForward() публичный статический Метод

public static StartForward ( IPAddress Interface_Addres, IPAddress Multicast_Address, int PortNumber, IPAddress Frwd_Interface_Addres, IPAddress Frwd_Multicast_Address, int Frwd_PortNumber ) : bool
Interface_Addres System.Net.IPAddress
Multicast_Address System.Net.IPAddress
PortNumber int
Frwd_Interface_Addres System.Net.IPAddress
Frwd_Multicast_Address System.Net.IPAddress
Frwd_PortNumber int
Результат bool
        public static bool StartForward(IPAddress Interface_Addres,  // IP address of the interface where the data is expected
                                       IPAddress Multicast_Address, // Multicast address of the expected data
                                       int PortNumber,
                                       IPAddress Frwd_Interface_Addres,  // IP address of the forward interface 
                                       IPAddress Frwd_Multicast_Address, // Multicast address of the forwarded data
                                       int Frwd_PortNumber)
        {
            // Open up outgoing socket
            // Open up a new socket with the net IP address and port number
            try
            {
                tx_sock = new UdpClient();
                tx_sock.JoinMulticastGroup(Frwd_Multicast_Address, Frwd_Interface_Addres);
                tx_iep = new IPEndPoint(Frwd_Multicast_Address, Frwd_PortNumber);

            }
            catch
            {
                MessageBox.Show("C1 TX FRD: Not possible! Make sure given IP address/port is a valid one on your system or not already used by some other process");
                return false;
            }

            // Check if recording is already in place, if so then
            // do not create a new incoming connection
            if (IsConnectionActive() == false)
            {
                // Open up a new socket with the net IP address and port number
                try
                {
                    rcv_sock = new UdpClient(PortNumber);
                    rcv_sock.JoinMulticastGroup(Multicast_Address, Interface_Addres);
                    rcv_iep = new IPEndPoint(IPAddress.Any, PortNumber);
                }
                catch
                {
                    MessageBox.Show("C1 RVC FRD: Not possible! Make sure given IP address/port is a valid one on your system or not already used by some other process");
                    return false;
                }

                KeepGoing = true;
                RequestStop = false;
                ListenForDataThread = new Thread(new ThreadStart(DOWork));
                ListenForDataThread.Start();
            }

            ForwardingEnabled = true;
            return true;
        }

Usage Example

Пример #1
0
 private void checkBoxF1_CheckedChanged(object sender, EventArgs e)
 {
     if (this.checkBoxF1.Checked == true)
     {
         if (RecForwConnection1.StartForward(
                 //Source parameters (always passed in, however the connection manager will use it just in the case the
                 // connection is not active already)
                 IPAddress.Parse(this.listBoxLocalAddr.Items[0].ToString()),
                 IPAddress.Parse(this.listBoxIPAddress.Items[0].ToString()),
                 int.Parse(this.listBoxPort.Items[0].ToString()),
                 // Forward parameters
                 IPAddress.Parse(this.listBoxForwardingInterface.Items[0].ToString()),
                 IPAddress.Parse(this.listBoxForwardingMulticast.Items[0].ToString()),
                 int.Parse(this.listBoxForwardingPort.Items[0].ToString())) == false)
         {
             this.checkBoxF1.Checked = false;
         }
         else
         {
             this.progressBarF1.Visible = true;
         }
     }
     else
     {
         RecForwConnection1.StopForwarding();
         this.progressBarF1.Visible = false;
     }
 }