示例#1
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);
        }
示例#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;
         }
     }
 }