public static FlightBoardModel getInstance()
 {
     if (instance == null)
     {
         instance = new FlightBoardModel();
     }
     return(instance);
 }
Example #2
0
        /*
         * The function starts the server, waits till we have connection from client, then starts reading the data
         * and sends the Lon and Lat values to the given fligtBoard.
         */
        public void Start(FlightBoardModel flightBoard)
        {
            //GetCurrentThread = Thread.CurrentThread;
            if (!running)
            {
                ISettingsModel app = ApplicationSettingsModel.Instance;
                //connect to the simulator
                TcpListener server = new TcpListener(IPAddress.Parse(app.FlightServerIP), app.FlightInfoPort);

                server.Start();

                //wait till we have a connection
                TcpClient client = server.AcceptTcpClient();
                NotConnected = false;
                NetworkStream stream = client.GetStream();

                while (!ShouldStop)
                {
                    byte[] buffer    = new byte[client.ReceiveBufferSize];
                    int    bytesRead = stream.Read(buffer, 0, client.ReceiveBufferSize);
                    string received  = Encoding.ASCII.GetString(buffer, 0, bytesRead);

                    Console.WriteLine("Received from client:" + received);
                    if (firstData)
                    {
                        string[] values = received.Split(',');
                        double   x      = Convert.ToDouble(values[0]);
                        double   y      = Convert.ToDouble(values[1]);
                        flightBoard.Lon = x;
                        flightBoard.Lat = y;
                        System.Console.WriteLine(ShouldStop);
                    }
                    else
                    {
                        if (counter == 2)
                        {
                            firstData = true;
                        }
                        else
                        {
                            counter++;
                        }
                    }
                }
            }
            System.Console.WriteLine("finish");
            NotConnected = true;
        }
 public Server(string ip, int port, FlightBoardModel flightBoardModel)
 {
     this.port             = port;
     this.ip               = ip;
     this.flightBoardModel = flightBoardModel;
 }