/// <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); }
//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); }
void Start() { client = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <TCPclient>(); if (client != null) { client.send("Start " + 0.5); } else { Debug.Log("no script"); } }
//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; } } }
public void Start() { mainSlider.maxValue = 0.5f; mainSlider.minValue = 0; client = new TCPclient(this); }