Esempio 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();
    }
Esempio n. 2
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;
    }
Esempio n. 3
0
        //[Fact(Skip = "Skipped")]
        public void StressTestUnreliable()
        {
            Util.Log("StressTestUnreliable");

            ComClient client = new ComClient(false);

            client.PortNumber       = this.server.Port;
            client.ListenPortNumber = this.server.Port + 1;

            client.BufferSize = 8192 * 10;

            Connect(ref client);
            server.Server.BeaconStop();

            int recvTestNum = 0;
            int sendTestNum = 0;

            //AddChannel
            TestClass testData = new TestClass();

            testData.intData    = 6;
            testData.floatData  = 6.6f;
            testData.stringData = "Are you human?";

            //Byte
            //Class
            client.AddChannel(new DataChannel <TestClass>((short)ChannelId.ClassUnRel, QosType.Unreliable, comp, enc, (node, data) =>
            {
                if (
                    data.intData == testData.intData &&
                    data.floatData == testData.floatData &&
                    data.stringData == testData.stringData
                    )
                {
                    recvTestNum++;
                }
            }, checkMode));

            Random random = new Random();

            sendTestNum = random.Next(500, 600);

            Util.Log("sendTestNum:" + sendTestNum);

            //Send
            for (int i = 0; i < sendTestNum; i++)
            {
                client.Send((short)ChannelId.ClassUnRel, testData);
            }


            Stopwatch sw = new Stopwatch();

            sw.Reset();
            sw.Start();

            while (true)
            {
                if (recvTestNum == sendTestNum)
                {
                    break;
                }
                else if (sw.Elapsed.Seconds >= 10)
                {
                    float percennt = (float)recvTestNum / (float)sendTestNum * 100.0f;
                    Util.Log("percent:" + percennt);
                    if (percennt < 80.0f)
                    {
                        client.Close();
                        throw new InvalidProgramException();
                    }
                    break;
                }

                Task.Delay(100);
            }
            sw.Stop();

            Disconnect(ref client);
        }
Esempio n. 4
0
        //[Fact(Skip = "Skipped")]
        public void SendReceiveRaw()
        {
            Util.Log("SendReceiveRaw");

            ComClient client = new ComClient(false);

            client.PortNumber       = this.server.Port;
            client.ListenPortNumber = this.server.Port + 1;

            Connect(ref client);
            server.Server.BeaconStop();

            //AddChannel
            bool boolCheck   = false;
            bool byteCheck   = false;
            bool shortCheck  = false;
            bool intCheck    = false;
            bool floatCheck  = false;
            bool doubleCheck = false;
            bool stringCheck = false;
            bool classCheck  = false;

            bool      boolData   = true;
            byte      byteData   = 246;
            short     shortData  = 361;
            int       intData    = 543;
            float     floatData  = 5.6f;
            double    doubleData = 32.5;
            string    stringData = "You are not human!";
            TestClass testData   = new TestClass();

            testData.intData    = 6;
            testData.floatData  = 6.6f;
            testData.stringData = "Are you human?";


            //Bool
            client.AddChannel(new DataChannel <bool>((short)ChannelId.BoolRaw, QosType.Reliable, comp, enc, (node, data) =>
            {
                if (data == boolData)
                {
                    boolCheck = true;
                }
            }, checkMode));

            //Byte
            client.AddChannel(new DataChannel <byte>((short)ChannelId.ByteRaw, QosType.Reliable, comp, enc, (node, data) =>
            {
                if (data == byteData)
                {
                    byteCheck = true;
                }
            }, checkMode));

            //Short
            client.AddChannel(new DataChannel <short>((short)ChannelId.ShortRaw, QosType.Reliable, comp, enc, (node, data) =>
            {
                if (data == shortData)
                {
                    shortCheck = true;
                }
            }, checkMode));

            //Int
            client.AddChannel(new DataChannel <int>((short)ChannelId.IntRaw, QosType.Reliable, comp, enc, (node, data) =>
            {
                if (data == intData)
                {
                    intCheck = true;
                }
            }, checkMode));

            //Float
            client.AddChannel(new DataChannel <float>((short)ChannelId.FloatRaw, QosType.Reliable, comp, enc, (node, data) =>
            {
                if (data == floatData)
                {
                    floatCheck = true;
                }
            }, checkMode));

            //Double
            client.AddChannel(new DataChannel <double>((short)ChannelId.DoubleRaw, QosType.Reliable, comp, enc, (node, data) =>
            {
                Util.Log("double:" + data);
                if (data == doubleData)
                {
                    doubleCheck = true;
                }
            }, checkMode));

            //String
            client.AddChannel(new DataChannel <string>((short)ChannelId.StringRaw, QosType.Reliable, comp, enc, (node, data) =>
            {
                if (data == stringData)
                {
                    stringCheck = true;
                }
            }, checkMode));

            //Class
            client.AddChannel(new DataChannel <TestClass>((short)ChannelId.ClassRaw, QosType.Reliable, comp, enc, (node, data) =>
            {
                Util.Log("class:" + data);
                if (
                    data.intData == testData.intData &&
                    data.floatData == testData.floatData &&
                    data.stringData == testData.stringData
                    )
                {
                    classCheck = true;
                }
            }, checkMode));


            //Send
            client.Send((short)ChannelId.BoolRaw, boolData);
            client.Send((short)ChannelId.ByteRaw, byteData);
            client.Send((short)ChannelId.ShortRaw, shortData);
            client.Send((short)ChannelId.IntRaw, intData);
            client.Send((short)ChannelId.FloatRaw, floatData);
            client.Send((short)ChannelId.DoubleRaw, doubleData);
            client.Send((short)ChannelId.StringRaw, stringData);
            client.Send((short)ChannelId.ClassRaw, testData);

            Stopwatch sw = new Stopwatch();

            sw.Reset();
            sw.Start();

            while (true)
            {
                if (boolCheck &&
                    byteCheck &&
                    shortCheck &&
                    intCheck &&
                    floatCheck &&
                    doubleCheck &&
                    stringCheck &&
                    classCheck
                    )
                {
                    break;
                }
                else if (sw.Elapsed.Seconds >= 2225)
                {
                    client.Close();
                    throw new TimeoutException();
                }

                Task.Delay(100);
            }
            sw.Stop();

            Disconnect(ref client);
        }