Example #1
0
 //get all of the commands and push them to the queue
 public void GetCommands(string ip, int port, int commandPort)
 {
     //create the TCPListener and start it
     server = new TcpListener(IPAddress.Parse(ip), port);
     System.Diagnostics.Debug.WriteLine("Server connecting on ip = {0} and port = {1}", ip, port);
     server.Start();
     //run until you get a connection
     while (true)
     {
         //accept the connection
         TcpClient client = server.AcceptTcpClient();
         System.Diagnostics.Debug.WriteLine("Server accepted client");
         //invoke the event for the command client to connect to the flight simulator
         connectEvent?.Invoke(ip, commandPort);
         //get the network stream from the client
         NetworkStream ns = client.GetStream();
         //run while there is a connection
         while (client.Connected)
         {
             //read information
             StreamReader reader  = new StreamReader(ns);
             string       command = reader.ReadLine();
             //push the information to the queue
             commands.AddElement(command);
         }
     }
 }
Example #2
0
 /*send a command for the client to send to the flight simulator*/
 public void SendData(string command)
 {
     //if the client is actually connected add the command to the queue
     if (serverThread != null)
     {
         commands.AddElement(command);
     }
 }