Example #1
0
        /// <summary>
        /// Initialize the Link with LiveTraffic
        ///  this will init the receiver and pace outbound messages every 10 sec
        ///  Connects to default ports
        /// </summary>
        /// <param name="hostIP">The LiveTraffic plugin host</param>
        /// <returns>True if successfull (else see Error content)</returns>
        public bool EstablishLink(string hostIP, uint numAcft, uint numVFR)
        {
            Logger.Instance.Log($"TrafficHandler-EstablishLink to: {hostIP}");
            if (!Valid)
            {
                return(false);
            }

            m_numAcft = numAcft;
            m_numVFR  = numVFR;

            m_userAcft = new UserAcft( );
            // setup Comm
            m_host = hostIP;
            try {
                LT_Traffic      = new UDPsender(m_host, RealTraffic.PortTrafficUDP);
                LT_Weather      = new UDPsender(m_host, RealTraffic.PortWeatherUDP);
                LTLink          = new TCPclient(m_host, RealTraffic.PortLinkTCP);
                LTLink.LTEvent += LTLink_LTEvent;
            }
            catch (Exception e) {
                Error = $"Error: {e.Message}";
                Logger.Instance.Log($"TrafficHandler: {Error}");
                return(false);
            }
            //
            Valid = LTLink.Connect( ); // if successful this triggers the reception of messages;
            if (!Valid)
            {
                Error = $"Error: {LTLink.Error}";
            }

            Logger.Instance.Log($"TrafficHandler: {Error}");
            return(Valid);
        }
Example #2
0
 //Connect dio socketa
 private void Connect(int port, sensorform neighbour)
 {
     while (!TCPclient.Connected)
     {
         try
         {
             TCPclient.Connect(IPAddress.Loopback, port);
         }
         catch (SocketException)
         {
             MessageBox.Show("Connecting unsuccessful.");
             break;
         }
     }
 }