示例#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);
        }
示例#2
0
        //Komunikacija između dva senzora
        private void Talk(sensorform neighbour)
        {
            byte[] buffer = Encoding.ASCII.GetBytes("get data");
            TCPclient.Send(buffer);
            byte[] recieved = new byte[1024];

            int record = TCPclient.Receive(recieved);

            byte[] input = new byte[record];
            Array.Copy(recieved, input, record);
            string recievedData = Encoding.ASCII.GetString(input);

            string mergedData = mergeData(recievedData);

            outbox.Enabled    = true;
            resultbox.Enabled = true;

            connectedto.Text = neighbour.username;


            xdata = mergedData;

            resultbox.Items.Clear();
            resultbox.Items.Add("Connected to: " + neighbour.username);
            resultbox.Items.Add("\t" + neighbour.username + " data: " + recievedData);
            resultbox.Items.Add("\tMerged data: " + mergedData);
        }
示例#3
0
 void Start()
 {
     client = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <TCPclient>();
     if (client != null)
     {
         client.send("Start " + 0.5);
     }
     else
     {
         Debug.Log("no script");
     }
 }
示例#4
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;
         }
     }
 }
示例#5
0
 public void Start()
 {
     mainSlider.maxValue = 0.5f;
     mainSlider.minValue = 0;
     client = new TCPclient(this);
 }