Exemplo n.º 1
0
    public MainWindow() : base(Gtk.WindowType.Toplevel)
    {
        Build();

        buttonSend.Clicked += (sender, e) =>
        {
            if (textviewInput.Buffer.Text.Length > 0)
            {
                client.Send(0, textviewInput.Buffer.Text);
                textviewInput.Buffer.Text = "";
            }
        };

        client.OnConnected += (node) =>
        {
            textviewInput.Sensitive = true;
            buttonSend.Sensitive    = true;
        };

        client.OnDisconnected += (node) =>
        {
            textviewInput.Sensitive = false;
            buttonSend.Sensitive    = false;
        };

        client.AddChannel(new DataChannel <string>(0, QosType.Reliable, Compression.None, (endPointIp, data) => { OnReceive(data); }));
        client.AcceptBeacon = true;
        client.Open();
    }
Exemplo n.º 2
0
        //[Fact(Skip = "Skipped")]
        public void OpenClose()
        {
            Util.Log("OpenClose");

            ComClient client = new ComClient(false);

            client.PortNumber       = this.server.Port;
            client.ListenPortNumber = this.server.Port + 1;
            client.Open();

            client.Close();
        }
Exemplo n.º 3
0
    public MainWindow() : base(Gtk.WindowType.Toplevel)
    {
        Build();

        buttonSend.Clicked += (sender, e) =>
        {
            if (textviewInput.Buffer.Text.Length > 0)
            {
                client.Send(0, textviewInput.Buffer.Text);
                textviewInput.Buffer.Text = "";
            }
        };

        buttonConnect.Clicked += (sender, e) =>
        {
            if (client.IsConnected)
            {
                client.Disconnect();
            }
            else
            {
                client.Connect("127.0.0.1");
            }
        };

        client.OnConnected += (node) =>
        {
            textviewInput.Sensitive = true;
            buttonSend.Sensitive    = true;
            buttonConnect.Label     = "Disconnect";
        };

        client.OnDisconnected += (node) =>
        {
            textviewInput.Sensitive = false;
            buttonSend.Sensitive    = false;
            buttonConnect.Label     = "Connect";
        };

        client.AddChannel(new DataChannel <string>(0, QosType.Reliable, Compression.LZ4, Encryption.Aes, (endPointIp, data) =>
        {
            OnReceive(data);
        }));

        client.ListenPortNumber = client.PortNumber + 1;

        client.Open();

        client.AcceptBeacon = true;
    }
Exemplo n.º 4
0
        void Connect(ref ComClient client)
        {
            bool      connected = false;
            Stopwatch sw        = new Stopwatch();

            client.SetBeaconAcceptFunction((data) => { if (data == "Test")
                                                       {
                                                           return(true);
                                                       }
                                                       else
                                                       {
                                                           return(false);
                                                       } });

            client.OnConnected += (node) =>
            {
                connected = true;
            };
            client.Open();
            client.AcceptBeacon = true;

            //server.Server.BeaconStart();
            //server.Server.SendConnectBeacon("127.0.0.1");

            client.Connect("127.0.0.1");

            sw.Start();
            while (true)
            {
                if (client.IsConnected && connected)
                {
                    break;
                }
                else if (sw.Elapsed.Seconds >= 3)
                {
                    client.Close();
                    server.Server.BeaconStop();
                    throw new TimeoutException();
                }
                Task.Delay(100);
            }
            sw.Stop();
        }