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); }); }); }
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)); }
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); }
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)); }
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(); } }
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"))); }
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)); }); }
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); }); }); }
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(); } }
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)); }