private static void ParsingThread()
        {
            // 1. Load and the data, depending on format
            owner.SafeUpdateStatus("Loading...", true);
            List <Point3D> LoadedPoints = LoadPointsFromLastFile();

            if (LoadedPoints == null)
            {
                return;
            }

            // 2. Instruct GUI to add these points to its display
            owner.SafeUpdateStatus("Creating point cloud...", false);
            owner.PlotPointDataThread(LoadedPoints);
        }
示例#2
0
        private void ListenerThread()
        {
            if (Thread.CurrentThread.Name == null)
            {
                Thread.CurrentThread.Name = "Network Thread";
            }

            connected = true;

            try
            {
                // Start listening for client requests.
                server.Start();

                // Buffer for reading data
                Byte[] bytes = new Byte[100000];

                // Enter the listening loop.
                while (connected)
                {
                    String s = "Waiting for a connection on " +
                               IPAddress.Parse(((IPEndPoint)server.LocalEndpoint).Address.ToString()) + ":" +
                               ((IPEndPoint)server.LocalEndpoint).Port.ToString();

                    owner.SafeUpdateStatus(s, false);


                    // Perform a blocking call to accept requests.
                    // You could also user server.AcceptSocket() here.
                    TcpClient client = server.AcceptTcpClient();

                    string clientIPAddress = "Connection from " + IPAddress.Parse(((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString());
                    owner.SafeUpdateStatus(clientIPAddress, false);

                    // Get a stream object for reading and writing
                    NetworkStream stream = client.GetStream();

                    int i;

                    // Loop to receive all the data sent by the client.

                    while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                    {
                        owner.SafeUpdateStatus("Received " + i + " bytes!", false);
                        owner.PlotIncomingData(bytes.SubArray(0, bytes.Length));
                    }

                    // Shutdown and end connection
                    owner.SafeUpdateStatus("Client disconnected.", false);
                    client.Close();
                } // while
            }
            catch (SocketException e)
            {
                if (e.SocketErrorCode != SocketError.Interrupted)   // This is normal when closing the connection manually, so ignore it.  Flag all others.
                {
                    MessageBox.Show("Listener SocketException: " + e.Message);
                }
            }
            catch (IOException)  // This is normal when client closes connection "forcibly"
            {
                ;
            }
            finally
            {
                // Stop listening for new clients.
                if (server != null)
                {
                    server.Stop();
                }

                owner.Invoke(new Action(() => owner.Disconnect()));   // Restores state of GUI buttons
            }
        }