Example #1
0
        public Form1()
        {
            InitializeComponent();
            comboBox1.Items.Add("View Most Ordered");
            comboBox1.Items.Add("View Average Party Size");
            comboBox1.Items.Add("View Average Order Cost");

            host = new cHost();
            host.Initialize(listbox_incoming_orders, listbox_incoming_requests);
        }
Example #2
0
        public void ListenForOrders(CheckedListBox orders, CheckedListBox requests)
        {
            TcpListener server = null;

            try
            {
                Int32     portNumber = 9999;
                IPAddress localip    = IPAddress.Parse("192.168.1.2");
                server = new TcpListener(localip, portNumber);
                server.Start();

                //Echo server loops forever, listening for clients
                for (; ;)
                {
                    //Accept the pending client connection and return a client
                    //initialized for communication
                    //This method will block until a connection is made
                    cHost es = new cHost(server.AcceptTcpClient());
                    es.SetState(true);
                    clients.Add(es);

                    //Allow this conversation to run in a new thread
                    // Thread serverThread = new Thread(new ThreadStart(es.Conversation));
                    // serverThread.Start();
                    Console.WriteLine("Creating thread");
                    Thread conversationthread = new Thread(() => es.Conversation(orders, requests));
                    conversationthread.Start();

                    //Loop back up and wait for another client
                    //Another thread is servicing this client
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e + " " + e.StackTrace);
            }
            finally
            {
                //Release the port and stop the server
                server.Stop();
            }
        }