예제 #1
0
        public void TestJsonLinkRequestWriteRead2()
        {
            // Arrange
            var address = new ProxySocketAddress();

            address.Port = 443;
            address.Host = "myhosttolinkto";

            var props = new SocketInfo();

            props.Address  = address;
            props.Family   = AddressFamily.InterNetwork;
            props.Protocol = ProtocolType.Udp;
            props.Type     = SocketType.Stream;
            props.Flags    = (uint)SocketFlags.Passive;

            for (Int32 i = 0; i < 10; i++)
            {
                props.Options.Add(Property <ulong> .Create((uint)(13 - i), (ulong)i));
            }

            var request = Message.Create(null, null, null, LinkRequest.Create(props));
            var stream  = new MemoryStream();

            // Act
            request.Encode(stream, CodecId.Json);
            byte[] buf      = Interop.MessageDecodeEncode(CodecId.Json, 1, stream.GetBuffer(), stream.Length, buffer, buffer.Length);
            var    returned = Serializable.Decode <Message>(new MemoryStream(buf), CodecId.Json);

            // Assert
            Assert.IsTrue(request.Equals(returned));
        }
예제 #2
0
        public void TestJsonLinkRequestWriteRead3()
        {
            // Arrange
            var address = new ProxySocketAddress();

            address.Port = 1;
            address.Host = "";

            var props = new SocketInfo();

            props.Address  = address;
            props.Family   = AddressFamily.Proxy;
            props.Protocol = ProtocolType.Unspecified;
            props.Type     = SocketType.Dgram;
            props.Flags    = (uint)SocketFlags.Internal;

            for (Int32 i = 0; i < 3; i++)
            {
                props.Options.Add(Property <ulong> .Create((uint)(13 - i), (ulong)i));
            }

            props.Options.Add(Property <IMulticastOption> .Create((uint)SocketOption.IpMulticastJoin,
                                                                  new Inet4MulticastOption {
                InterfaceIndex = 5, Address = BitConverter.GetBytes((int)234)
            }));
            var ab = new byte[16];

            new Random().NextBytes(ab);
            props.Options.Add(Property <IMulticastOption> .Create((uint)SocketOption.IpMulticastLeave,
                                                                  new Inet6MulticastOption {
                InterfaceIndex = 5, Address = ab
            }));

            var request = Message.Create(null, null, null, LinkRequest.Create(props));
            var stream  = new MemoryStream();

            // Act
            request.Encode(stream, CodecId.Json);
            byte[] buf      = Interop.MessageDecodeEncode(CodecId.Json, 1, stream.GetBuffer(), stream.Length, buffer, buffer.Length);
            var    returned = Serializable.Decode <Message>(new MemoryStream(buf), CodecId.Json);

            // Assert
            Assert.IsTrue(request.Equals(returned));
        }