Beispiel #1
0
        /// <summary>
        /// The start of the client program
        /// </summary>
        public Client()
        {
            Console.WriteLine("Start");
            computer = new Computer(this);
            InitComputer();

            InitLUA();
            Console.WriteLine("Looking out for Server...");
            string ServerIP = null;
            do
            {
               // ServerIP = Messaging.RetrieveMulitcastIP();
                ServerIP = Messaging.RetrieveBroadcastIP();
            } while (ServerIP == null || ServerIP == " ");
            Console.WriteLine("SERVERIP :: " + ServerIP);
            Console.WriteLine("Found the server!");

            CommandMode(ServerIP);
        }
Beispiel #2
0
        private async void button1_Click(object sender, EventArgs e)
        {
            var checkedButton = Controls.OfType <RadioButton>()
                                .FirstOrDefault(r => r.Checked);

            string command = checkedButton.Text;

            if (command.Equals("Add"))
            {
                SendMessageFromSocket("SAVE");

                Computer computer = new Computer();
                computer.Id    = textBox3.Text;
                computer.Price = textBox1.Text;
                computer.Brand = textBox2.Text;

                var serializedComp = computer.SerializeToString();
                SendAndGetMessageFromSocket(serializedComp);
            }

            if (command.Equals("Edit"))
            {
                SendMessageFromSocket("EDIT");

                Computer computer = new Computer();
                computer.Id    = textBox3.Text;
                computer.Price = textBox1.Text;
                computer.Brand = textBox2.Text;

                var serializedComp = computer.SerializeToString();
                SendAndGetMessageFromSocket(serializedComp);
            }

            if (command.Equals("Delete"))
            {
                SendMessageFromSocket("DELETE");

                Computer computer = new Computer();
                computer.Id    = textBox3.Text;
                computer.Price = textBox1.Text;
                computer.Brand = textBox2.Text;

                var serializedComp = computer.SerializeToString();
                SendAndGetMessageFromSocket(serializedComp);
            }

            if (command.Equals("Find by brand"))
            {
                if (textBox2.Text.Equals(""))
                {
                    SendAndGetMessageFromSocket("GET_ALL");
                }
                else
                {
                    SendMessageFromSocket("FIND");

                    Computer computer = new Computer();
                    computer.Id    = "";
                    computer.Price = "";
                    computer.Brand = textBox2.Text;

                    var serializedComp = computer.SerializeToString();
                    SendAndGetMessageFromSocket(serializedComp);
                }
            }

            textBox.Text += "\r\ndata has sent to the server";
        }