Ejemplo n.º 1
0
        public void Run(int serverPort)
        {
            client = new MessageClient(
                     new FramedClient(new SocketClient(useIPv6: true)),
                     new ProtoBufStacksSerializer(),
                     new ClientMessageHandler());

            client.PreLoadTypesFromAssemblyOfType<TemperatureResponse>();

            client.Connect(new IPEndPoint(IPAddress.IPv6Loopback, serverPort))
                  .Subscribe(_ =>
                  {
                      Console.WriteLine("Querying for temperature in London, Warsaw, Madrid");
                      client.Send(new TemperatureRequest { City = "London" });
                      client.Send(new TemperatureRequest { City = "Warsaw" });
                      client.Send(new TemperatureRequest { City = "Madrid" });
                  });
        }
Ejemplo n.º 2
0
            public void Sending_message_should_succeed_when_packet_types_are_preloaded()
            {
                var c = new MessageClient(framedClient, serializer.Object, messageHandler.Object);

                c.PreLoadTypesFromAssemblyOfType<TestData>();

                serializer.Setup(s => s.Serialize(It.IsAny<TestData>(), It.IsAny<MemoryStream>()))
                          .Callback((TestData d, MemoryStream ms) =>
                          {
                              ms.Write(new byte[] { 0, 1, 2, 3, 4 }, 0, 5);
                          });

                rawClient.Setup(rc => rc.Send(It.IsAny<byte[]>())).Callback((byte[] b) =>
                {
                    var length = BitConverter.ToInt32(b, 0);
                    var messageId = BitConverter.ToInt32(b, 4);

                    Assert.Equal(4 + 4 + 5, length);
                    Assert.Equal(4 + 4 + 5, b.Length);
                    Assert.Equal(3, messageId);
                    Assert.Equal(new byte[] { 0, 1, 2, 3, 4 }, new ArraySegment<byte>(b, 8, 5));
                });

                c.Send(CreateSampleTestData());
            }