Exemplo n.º 1
0
    public void Start()
    {
        string key  = "test_key";
        string data = "testdata for key";

        string key2  = "test_key2";
        string data2 = "testdata for key2";

        PySSSMQ_client client = new PySSSMQ_client();

        if (!client.Connect("127.0.0.1"))
        {
            Console.WriteLine("Could not connect to server");
            return;
        }

        Console.WriteLine("Connected to server");

        client.AttachReceiveEvent(this.ReceiveData);
        Console.WriteLine("this.Recieved is attached to PySSSMQ_client");

        Console.WriteLine("Pull " + key);
        client.Pull(key);
        System.Threading.Thread.Sleep(1000);

        Console.WriteLine("Seding to server: key = " + key + ", data = " + data);
        client.Send(key, data);

        System.Threading.Thread.Sleep(1000);
        Console.WriteLine("Seding to server: key = " + key2 + ", data = " + data2);
        client.Send(key2, data2);

        System.Threading.Thread.Sleep(1000);
        Console.WriteLine("Pull " + key);
        client.Pull(key);

        System.Threading.Thread.Sleep(1000);
    }
Exemplo n.º 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);
            }
        }