예제 #1
0
파일: Program.cs 프로젝트: KennyDizi/IoFx
        private static void AcceptChannelTest()
        {
            var binding     = new NetTcpBinding();
            var listener    = binding.Start(address);
            var connections = from channel in listener.GetChannels()
                              select new
            {
                Messages = channel.GetMessages(),
                Response = channel.GetConsumer()
            };

            connections.Subscribe(item =>
            {
                item.Response.Publish(Message.CreateMessage(binding.MessageVersion, "Test", "Echo:" + "Connected"));

                /*
                 *    (from message in channel.Messages
                 *     let input = message.GetBody<string>()
                 *     from response in new[] { Message.CreateMessage(version, "", "Echo:" + input) }
                 *     select response)
                 *    .Subscribe(channel.Response);
                 *
                 */
                item.Messages.Subscribe((message) =>
                {
                    var input  = message.GetBody <string>();
                    var output = Message.CreateMessage(binding.MessageVersion, "", "Echo:" + input);
                    item.Response.Publish(output);
                });
            });
        }
예제 #2
0
        public IDisposable StartServer()
        {
            var monitor = new ConnectionRateMonitor();
            var binding = new NetTcpBinding {
                Security = { Mode = SecurityMode.None }
            };
            var listener = binding.Start(_address);

            Console.WriteLine("Listening on " + listener.Uri);

            listener.GetChannels()
            .SubscribeOn(System.Reactive.Concurrency.ThreadPoolScheduler.Instance)
            .Subscribe(c =>
            {
                monitor.OnConnect();
                c.GetMessages()
                .Subscribe(
                    m => monitor.OnMessage(),
                    ex => monitor.OnDisconnect(),
                    monitor.OnDisconnect);
            });

            monitor.Start();

            return(Disposable.Create(listener.Abort));
        }
예제 #3
0
        public IDisposable StartServer()
        {
            var monitor = new ConnectionRateMonitor();
            var binding = new NetTcpBinding { Security = { Mode = SecurityMode.None } };
            var listener = binding.Start(this.ConnectArguments.CreateNetTcpAddress());
            Console.WriteLine("Listening on {0} for {1}", listener.Uri, typeof(SimpleObject).Name);

            listener.GetChannels()
                .SubscribeOn(System.Reactive.Concurrency.ThreadPoolScheduler.Instance)
                .Subscribe(c =>
                {
                    monitor.OnConnect();
                    c.GetMessages()
                        .Subscribe(
                            m =>
                            {
                                monitor.OnMessage();
                                var obj = m.GetBody<SimpleObject>();
                            },
                        ex => monitor.OnDisconnect(),
                        monitor.OnDisconnect);
                });

            monitor.Start();
            return Disposable.Create(listener.Abort);
        }
예제 #4
0
        public static IDisposable ChannelModelDispatcher()
        {
            var binding = new NetTcpBinding()
            {
            };

            binding.Security.Mode = SecurityMode.None;
            var listener = binding.Start(Address);
            var res      = listener.OnMessage()
                           .Do(m => Console.WriteLine(m.Message.Headers.Action))
                           .Subscribe(
                r =>
            {
                Customer c = r.Message.DecodeGetOrder();
                Console.WriteLine(c.Name);
                var output = new Order {
                    Name = c.Name + ":Order"
                };
                var response = output.EncodeGetOrderResponse(r.Message);
                r.Publish(response);
            }
                );

            return(Disposable.Create(listener.Abort));
        }
예제 #5
0
        public int GetMessages(int numberOfMessages)
        {
            var binding = new NetTcpBinding {
                Security = { Mode = SecurityMode.None }
            };
            var listener = binding.Start(_address);
            var tcs      = new TaskCompletionSource <int>();

            try
            {
                int count = 0;
                var watch = new Stopwatch();
                watch.Start();
                listener.GetChannels().Subscribe(c =>
                {
                    Console.WriteLine("Channel accepted");
                    c.GetMessages().Subscribe(m =>
                    {
                        // Console.WriteLine("Message received");
                        var bytes = m.GetBody <byte[]>();
                        // Console.WriteLine(Encoding.ASCII.GetString(bytes));
                        if (Interlocked.Increment(ref count) == numberOfMessages)
                        {
                            tcs.SetResult(numberOfMessages);
                        }
                    },
                                              tcs.SetException);
                }, tcs.SetException);

                SendMessages(binding, numberOfMessages, _address);

                Observable.Interval(TimeSpan.FromSeconds(1))
                .TakeWhile(_ => count <= numberOfMessages)
                .Subscribe(_ => Console.WriteLine("Received {0} messages at {1} messages/sec",
                                                  count,
                                                  count / watch.Elapsed.TotalSeconds));

                tcs.Task.Wait(Defaults.LongTestWaitTime);
                watch.Stop();
                var seconds = watch.Elapsed.TotalSeconds;
                Console.WriteLine("Received {0} messages in {1} seconds : {2} messages/sec",
                                  count,
                                  seconds,
                                  count / seconds);

                return(count);
            }
            finally
            {
                listener.Abort();
            }
        }
예제 #6
0
        public static void Main(string args)
        {
            var binding = new NetTcpBinding {
                Security = { Mode = SecurityMode.None }
            };
            var listener = binding.Start("net.tcp://localhost:8080/");

            Console.WriteLine("Listening on " + listener.Uri);

            listener.GetChannels()
            .Subscribe(channel =>
                       channel.GetMessages()
                       .Subscribe(
                           m => Console.WriteLine("Message Received."),
                           ex => Console.WriteLine(ex.Message),
                           () => Console.WriteLine("Disconnected")));
        }
예제 #7
0
파일: Program.cs 프로젝트: KennyDizi/IoFx
        private static void MessageTest()
        {
            NetTcpBinding b        = new NetTcpBinding();
            var           listener = b.Start(address);

            listener
            .OnConnect()
            .Do(c => Console.WriteLine("Channel accepted"))
            .OnMessage()
            .Do(m => Console.WriteLine("Received " + m.Message.Headers.Action))
            .Subscribe(
                r =>
            {
                var input = r.Message.GetBody <string>();
                r.Publish(Message.CreateMessage(b.MessageVersion, "", "Echo:" + input));
                r.Publish(Message.CreateMessage(b.MessageVersion, "", "Echo:" + input));
            });
        }
예제 #8
0
파일: Program.cs 프로젝트: KennyDizi/IoFx
        private static void ChannelConnectTest()
        {
            var netTcpBibnding = new NetTcpBinding();
            var listener       = netTcpBibnding.Start(address);

            listener.GetChannels().Subscribe(channel => {
                channel.GetMessages().Subscribe(message =>
                {
                });
            });
            listener.OnConnect(channel =>
            {
                channel.Subscribe(message =>
                {
                    var input    = message.GetBody <string>();
                    var response = Message.CreateMessage(netTcpBibnding.MessageVersion, "", "Echo:" + input);
                    channel.Publish(message);
                });
            });
        }
예제 #9
0
        public void AcceptChannel()
        {
            var binding = new NetTcpBinding();

            binding.Security.Mode = SecurityMode.None;

            var listener = binding.Start(address);

            Scheduler.CurrentThread.Catch <Exception>((e) =>
            {
                Trace.WriteLine(e.Message);
                return(true);
            });
            try
            {
                listener
                .OnConnect()
                .Subscribe(
                    channel =>
                {
                    var responses = channel.Select(message =>
                    {
                        var input = message.GetBody <string>();
                        return(Message.CreateMessage(version, "", "Echo:" + input));
                    });

                    responses.Subscribe(channel.Publish);

                    //(from message in channel
                    // let input = message.GetBody<string>()
                    // select Message.CreateMessage(version, "", "Echo:" + input))
                    // .Subscribe(channel.Publish);
                });

                SendMessages();
            }
            finally
            {
                listener.Abort();
            }
        }
예제 #10
0
        public static IDisposable StartService()
        {
            //StartWcfService(address);
            var binding = new NetTcpBinding()
            {
            };

            binding.Security.Mode = SecurityMode.None;
            var listener = binding.Start(Address);

            listener
            .OnMessage()
            .OnGetOrder(c =>
            {
                Console.WriteLine(c.Name);
                return(new Order {
                    Name = c.Name + ":Order"
                });
            });

            return(Disposable.Create(listener.Abort));
        }