Exemple #1
0
 /// <summary>
 /// Used when you wish to update data in the dataStorage, and transmit to PySSSMQ-clients
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public void setData(String key, String value)
 {
     storeData(key, value);
     if (client.IsConnected())
     {
         client.Send(key, value);
     }
 }
Exemple #2
0
        public void ConnectToServer(object sender, EventArgs e)
        {
            if (!connected)
            {
                Console.WriteLine("You pressed the 'Connect'-button, you clever you... :-)");
                pySSSMQStatus.Text = "PySSSMQ: CONNECTING";
                kRPCStatus.Text    = "   kRPC: CONNECTING";

                try
                {
                    IPAddress[]          connectionAdrs = Dns.GetHostAddresses(ipAddr.Text);
                    System.Net.IPAddress IP             = connectionAdrs[0];         // IPv4

                    // Store connection IP
                    this.connectionIP = IP.ToString();

                    connectionName = name.Text;

                    connection = new Connection(name: connectionName, address: IP);

                    krpc        = connection.KRPC();
                    spaceCenter = connection.SpaceCenter();

                    streamCollection.setConnection(connection);

                    // Setup graphable data
                    setupChartData(streamCollection);

                    kRPCStatus.Text = "   kRPC: CONNECTED";
                    connected       = true;
                }
                catch (System.Net.Sockets.SocketException)
                {
                    MessageBox.Show("KRPC SERVER NOT RESPONDING");
                    kRPCStatus.Text = "   kRPC: NOT CONNECTED";
                }
                catch (System.FormatException)
                {
                    MessageBox.Show("NOT A VALID IP-ADDRESS");
                    kRPCStatus.Text = "   kRPC: NOT CONNECTED";
                }
                catch (System.IO.IOException)
                {
                    MessageBox.Show("IO ERROR");
                    kRPCStatus.Text = "   kRPC: NOT CONNECTED";
                }

                // Connect to pySSMQ
                try
                {
                    pySSSMQ.Connect(connectionIP);
                    pySSSMQ.AttachReceiveEvent(pySSSMQ_handler.receive);
                    if (pySSSMQ.IsConnected())
                    {
                        pySSSMQStatus.Text = "PySSSMQ: CONNECTED";
                        dataStorage.Pull();
                    }
                    else
                    {
                        pySSSMQStatus.Text = "PySSSMQ: NOT CONNECTED";
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.GetType() + ":" + ex.Message);
                    pySSSMQStatus.Text = "PySSSMQ: NOT CONNECTED";
                }
            }
            else
            {
                MessageBox.Show("Already Connected", "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }