Example #1
0
        public void Run()
        {
            ReactiveMessageClient <IServerPacketHandler> client = null;

            service = new MarketService();
            server  = new SocketServer(new IPEndPoint(IPAddress.Loopback, 0));

            server.Connected.Subscribe(c =>
            {
                client = new ReactiveMessageClient <IServerPacketHandler>(
                    new FramedClient(c),
                    new ProtoBufStacksSerializer());
                client.PreLoadTypesFromAssemblyOfType <Price>();

                // Here is the subscription to all the packets.
                // `.Packets` is an implementation of interface
                // given when message client was defined, so
                // every packet has a strongly typed `IObservable<TPacket>`
                // to subscribe to.
                client.Packets.RegisterSymbol.Subscribe(req =>
                {
                    if (req.Register)
                    {
                        service.RegisterSymbol(req.Symbol);
                    }
                    else
                    {
                        service.UnregisterSymbol(req.Symbol);
                    }
                });
            });

            // Service will only report registered price changes.
            // In this sample, this observer should not run
            // for 4 seconds after application start.
            service.PricesChanged.Subscribe(prices =>
            {
                Console.WriteLine("Services reported that prices changed");

                // Send new prices to client.
                foreach (var p in prices)
                {
                    if (client != null)
                    {
                        client.Send(p);
                    }
                }
            });

            server.Start();
            this.ServerPort = server.BindEndPoint.Port;
        }
Example #2
0
        public void Run()
        {
            ReactiveMessageClient<IServerPacketHandler> client = null;

            service = new MarketService();
            server = new SocketServer(new IPEndPoint(IPAddress.Loopback, 0));

            server.Connected.Subscribe(c =>
                {
                    client = new ReactiveMessageClient<IServerPacketHandler>(
                                    new FramedClient(c),
                                    new ProtoBufStacksSerializer());
                    client.PreLoadTypesFromAssemblyOfType<Price>();

                    // Here is the subscription to all the packets.
                    // `.Packets` is an implementation of interface
                    // given when message client was defined, so
                    // every packet has a strongly typed `IObservable<TPacket>`
                    // to subscribe to.
                    client.Packets.RegisterSymbol.Subscribe(req =>
                        {
                            if (req.Register)
                                service.RegisterSymbol(req.Symbol);
                            else
                                service.UnregisterSymbol(req.Symbol);
                        });
                });

            // Service will only report registered price changes.
            // In this sample, this observer should not run 
            // for 4 seconds after application start.
            service.PricesChanged.Subscribe(prices =>
                {
                    Console.WriteLine("Services reported that prices changed");

                    // Send new prices to client.
                    foreach (var p in prices)
                    {
                        if (client != null)
                            client.Send(p);
                    }
                });

            server.Start();
            this.ServerPort = server.BindEndPoint.Port;
        }