Exemple #1
0
        public void Communications(object socket)
        {
            Socket TCP_socket = (Socket)socket;

            // Create a new client object
            TCP_Model _ClientModel = new TCP_Model(TCP_socket);

            UpdateInfoBox("The Mobile Device has been joined \r\n");
            string XMLDataFile = "";

            while (true)
            {
                //Wait for the client data

                string XMLData = _ClientModel.Get_From_TCP();   // block until client sends XML message
                if (XMLData != null)
                {
                    UpdateInfoBox("Device is sending\r\n");
                    UpdateCommBox(XMLData + "\r\n");
                    XMLDataFile += XMLData;
                }
                else
                {
                    UpdateInfoBox("No more data\r\n");
                    break;
                }
            }

            // save the file into C:\FAFOS\InspectionData\In
            System.IO.File.WriteAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory)
                                        + "\\Resources\\inspection.xml", XMLDataFile);
            UpdateInfoBox("The Inspection results file is saved in \r\n" + System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory)
                          + "\\Resources\\inspection.xml");
        }
Exemple #2
0
        public void Communications(object socket)
        {
            Socket TCP_socket = (Socket)socket;

            // Create a new client object
            TCP_Model _ClientModel = new TCP_Model(TCP_socket);

            UpdateInfoBox("The Mobile Device has been joined \r\n");
            string XMLDataFile = "";
            while (true)
            {
                //Wait for the client data

                string XMLData = _ClientModel.Get_From_TCP();   // block until client sends XML message
                if (XMLData != null)
                {
                    UpdateInfoBox("Device is sending\r\n");
                    UpdateCommBox(XMLData + "\r\n");
                    XMLDataFile += XMLData;

                }
                else
                {
                    UpdateInfoBox("No more data\r\n");
                    break;
                }
            }

            // save the file into C:\FAFOS\InspectionData\In
            System.IO.File.WriteAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory)
                   + "\\Resources\\inspection.xml", XMLDataFile);
            UpdateInfoBox("The Inspection results file is saved in \r\n" + System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory)
                   + "\\Resources\\inspection.xml");
        }
Exemple #3
0
        public void ListenForClients()
        {
            // Create a model to listen from clients
            _TCPModel = new TCP_Model(Int32.Parse(_fromMobileView.GetPortNumber()));

            // Update the view
            UpdateServerIP(_TCPModel.ServerIP.ToString());

            while (true)
            {
                UpdateInfoBox("Server is waiting for new connection" + "\r\n");

                //blocks until a client has connected to the server
                Socket TCPsocket = _TCPModel.AcceptOneClient();

                //create a thread to handle communication with connected client
                clientThread = new Thread(new ParameterizedThreadStart(Communications));
                clientThread.IsBackground = true; // to stop all threads when application is terminated
                clientThread.Start(TCPsocket);
            }
        }
Exemple #4
0
        public void ListenForClients()
        {
            // Create a model to listen from clients
            _TCPModel = new TCP_Model(Int32.Parse(_fromMobileView.GetPortNumber()));

            // Update the view
            UpdateServerIP(_TCPModel.ServerIP.ToString());

            while (true)
            {
                UpdateInfoBox("Server is waiting for new connection" + "\r\n");

                //blocks until a client has connected to the server
                Socket TCPsocket = _TCPModel.AcceptOneClient();

                //create a thread to handle communication with connected client
                clientThread = new Thread(new ParameterizedThreadStart(Communications));
                clientThread.IsBackground = true; // to stop all threads when application is terminated
                clientThread.Start(TCPsocket);
            }
        }