예제 #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            bool      ricevi    = true;
            UdpClient udpClient = new UdpClient(M.getIP(), 82);

            Byte[] sendBytes = Encoding.ASCII.GetBytes("b");
            udpClient.Send(sendBytes, sendBytes.Length);
            while (ricevi)
            {
                Byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);
                textBox1.Text += string.Join(" ", receiveBytes);
                string s = System.Text.Encoding.UTF8.GetString(receiveBytes);
                //MessageBox.Show(s);
                if (s == "s")
                {
                    label4.Text      = "Connesso alla rete";
                    label4.ForeColor = Color.Green;
                    button4.Visible  = true;
                    M.setConn();
                    ricevi = false;
                }
                //Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { }));
            }

            /*inizioric = false;
             * fineric = true;
             * contrconn = true;
             * P.Write("b");*/
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            bool      ricevi    = true;
            UdpClient udpClient = new UdpClient(M1.getIP(), 82);

            Byte[] sendBytes = Encoding.ASCII.GetBytes("b");
            udpClient.Send(sendBytes, sendBytes.Length);
            while (ricevi)
            {
                Byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);
                string s            = System.Text.Encoding.UTF8.GetString(receiveBytes);
                //MessageBox.Show(s);
                if (s == "s")
                {
                    button3.Enabled   = true;
                    label12.ForeColor = Color.Green;
                    M1.setConn();
                    ricevi = false;
                }
                MessageBox.Show("Primo fatto");
                //Thread.Sleep(4000);
                //UdpClient udpClient2 = new UdpClient(M2.getIP(), 82);
                //udpClient2.Send(sendBytes, sendBytes.Length);
                //while (ricevi)
                //{
                //    Byte[] receiveBytes2 = receivingUdpClient.Receive(ref RemoteIpEndPoint);
                //    s = System.Text.Encoding.UTF8.GetString(receiveBytes2);
                //    //MessageBox.Show(s);
                //    if (s == "s")
                //    {
                //        button3.Enabled = true;
                //        label13.ForeColor = Color.Green;
                //        M2.setConn();
                //        ricevi = false;
                //    }
                //    //Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { }));
                //}
            }
        }