Esempio n. 1
0
        public void FrameMasked()
        {
            var framer = new WebSocketFramer(1024);

            var val          = new byte[] { 1, 2, 3 };
            var buffer       = framer.Frame(val, true);
            var headerLength = 6;

            Assert.Equal(headerLength + val.Length, buffer.Length);
            Assert.Equal(0x82, buffer[0]);
            Assert.Equal(0x83, buffer[1]);
            Console.WriteLine(BitConverter.ToString(buffer));
            Console.WriteLine(BitConverter.ToString(buffer, headerLength, val.Length));
            Console.WriteLine(BitConverter.ToString(buffer, headerLength - 4, 4));
            Assert.Equal(new byte[] { 1, 2, 3 }, WebSocketFramer.EnDecode(buffer, headerLength, val.Length, buffer, headerLength - 4));
        }
Esempio n. 2
0
        public void EnDecode()
        {
            var val     = new byte[] { 1, 2, 3 };
            var mask    = new byte[] { 0x0A, 0x0B, 0x0C, 0x0D };
            var encoded = WebSocketFramer.EnDecode(val, 0, val.Length, mask, 0);
            var decoded = WebSocketFramer.EnDecode(encoded, 0, val.Length, mask, 0);

            Assert.Equal(new byte[] { 1 ^ 0x0A, 2 ^ 0x0B, 3 ^ 0x0C }, encoded);
            Assert.Equal(new byte[] { 1, 2, 3 }, decoded);

            val     = new byte[] { 1, 2, 3, 4, 5, 6 };
            mask    = new byte[] { 0x0A, 0x0B, 0x0C, 0x0D };
            encoded = WebSocketFramer.EnDecode(val, 0, val.Length, mask, 0);
            decoded = WebSocketFramer.EnDecode(encoded, 0, val.Length, mask, 0);
            Assert.Equal(new byte[] { 1 ^ 0x0A, 2 ^ 0x0B, 3 ^ 0x0C, 4 ^ 0x0D, 5 ^ 0x0A, 6 ^ 0x0B }, encoded);
            Assert.Equal(new byte[] { 1, 2, 3, 4, 5, 6 }, decoded);

            var combined = new byte[] { 0, 0, 0, 1, 2, 3, 0x0A, 0x0B, 0x0C, 0x0D, 0, 0, 0 };

            encoded = WebSocketFramer.EnDecode(combined, 3, 3, combined, 6);
            decoded = WebSocketFramer.EnDecode(encoded, 0, 3, combined, 6);
            Assert.Equal(new byte[] { 1 ^ 0x0A, 2 ^ 0x0B, 3 ^ 0x0C }, encoded);
            Assert.Equal(new byte[] { 1, 2, 3 }, decoded);
        }