Ejemplo n.º 1
0
        private void StreamTestAsync(bool enableCrypt, bool reconn, int port)
        {
            var stream = new SnetStream(1024, enableCrypt);

            var ar = stream.BeginConnect("127.0.0.1", port, null, null);

            stream.WaitConnect(ar);

            for (int i = 0; i < 1000; i++)
            {
                var a = RandBytes(100);
                var b = a;
                var c = new byte[a.Length];

                if (enableCrypt)
                {
                    b = new byte[a.Length];
                    Buffer.BlockCopy(a, 0, b, 0, a.Length);
                }

                IAsyncResult ar1 = stream.BeginWrite(a, 0, a.Length, null, null);
                stream.EndWrite(ar1);

                if (reconn && i % 100 == 0)
                {
                    if (!stream.TryReconn())
                    {
                        Assert.Fail();
                    }
                }

                IAsyncResult ar2 = stream.BeginRead(c, 0, c.Length, null, null);
                stream.EndRead(ar2);

                if (!BytesEquals(b, c))
                {
                    Assert.Fail();
                }
            }

            stream.Close();
        }
Ejemplo n.º 2
0
        private void StreamTest(bool enableCrypt, bool reconn, int port)
        {
            var stream = new SnetStream(1024, enableCrypt);

            stream.Connect("127.0.0.1", port);

            for (int i = 0; i < 10000; i++)
            {
                var a = RandBytes(100);
                var b = a;
                var c = new byte[a.Length];

                if (enableCrypt)
                {
                    b = new byte[a.Length];
                    Buffer.BlockCopy(a, 0, b, 0, a.Length);
                }

                stream.Write(a, 0, a.Length);

                if (reconn && i % 100 == 0)
                {
                    if (!stream.TryReconn())
                    {
                        Assert.Fail();
                    }
                }

                for (int n = c.Length; n > 0;)
                {
                    n -= stream.Read(c, c.Length - n, n);
                }

                if (!BytesEquals(b, c))
                {
                    Assert.Fail();
                }
            }

            stream.Close();
        }