示例#1
0
        public void ClientReceiveTimeout()
        {
            IMessagingSystemFactory aMessaging = new WebSocketMessagingSystemFactory()
            {
                ReceiveTimeout = TimeSpan.FromMilliseconds(1000)
            };
            IDuplexOutputChannel anOutputChannel = aMessaging.CreateDuplexOutputChannel("ws://127.0.0.1:8046/");
            IDuplexInputChannel  anInputChannel  = aMessaging.CreateDuplexInputChannel("ws://127.0.0.1:8046/");

            try
            {
                ManualResetEvent aConnectionClosed = new ManualResetEvent(false);
                anOutputChannel.ConnectionClosed += (x, y) =>
                {
                    EneterTrace.Info("Connection closed.");
                    aConnectionClosed.Set();
                };

                anInputChannel.StartListening();
                anOutputChannel.OpenConnection();

                EneterTrace.Info("Connection opened.");

                // According to set receive timeout the client should get disconnected within 1 second.
                //aConnectionClosed.WaitOne();
                Assert.IsTrue(aConnectionClosed.WaitOne(3000));
            }
            finally
            {
                anOutputChannel.CloseConnection();
                anInputChannel.StopListening();
            }
        }
示例#2
0
        public void Setup()
        {
            //EneterTrace.DetailLevel = EneterTrace.EDetailLevel.Debug;
            //EneterTrace.TraceLog = new StreamWriter("d:/tracefile.txt");

            MessagingSystemFactory = new WebSocketMessagingSystemFactory();
            ChannelId = "ws://127.0.0.1:8091/";
        }
        static void Main(string[] args)
        {


            // Create broker.
            IDuplexBrokerFactory aBrokerFactory = new DuplexBrokerFactory();
            IDuplexBroker aBroker = aBrokerFactory.CreateBroker();

            // Communicate using WebSockets.
            IMessagingSystemFactory aMessaging = new WebSocketMessagingSystemFactory();
            IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel("ws://127.0.0.1:8843/CpuUsage/");

            anInputChannel.ResponseReceiverConnected += (x, y) =>
            {
                Console.WriteLine("Connected client: " + y.ResponseReceiverId);
            };
            anInputChannel.ResponseReceiverDisconnected += (x, y) =>
            {
                Console.WriteLine("Disconnected client: " + y.ResponseReceiverId);
            };

            // Attach input channel and start listeing.
            aBroker.AttachDuplexInputChannel(anInputChannel);


            var tokenSource = new CancellationTokenSource();

            var sendMonitoringMessages = Task.Run(() => SendMonitoringMessages(aBroker, tokenSource.Token), tokenSource.Token);

            Console.WriteLine("CpuUsageService is running press ENTER to stop.");
            Console.ReadLine();
            tokenSource.Cancel();

            try
            {
                sendMonitoringMessages.Wait();
            }
            catch (AggregateException)
            {
            }
            catch (TaskCanceledException)
            {
            }

            // Detach the input channel and stop listening.
            aBroker.DetachDuplexInputChannel();
        }
        public void Setup()
        {
            //EneterTrace.DetailLevel = EneterTrace.EDetailLevel.Debug;
            //EneterTrace.TraceLog = new StreamWriter("d:/tracefile.txt");
            //EneterTrace.StartProfiler();

            // Generate random number for the port.
            string aPort = RandomPortGenerator.Generate();

            MessagingSystemFactory = new WebSocketMessagingSystemFactory(new EasyProtocolFormatter());
            ChannelId = "ws://127.0.0.1:" + aPort + "/";

            this.CompareResponseReceiverId = false;
            this.myRequestMessage          = new byte[] { (byte)'M', (byte)'E', (byte)'S', (byte)'S', (byte)'A', (byte)'G', (byte)'E' };
            this.myResponseMessage         = new byte[] { (byte)'R', (byte)'E', (byte)'S', (byte)'P', (byte)'O', (byte)'N', (byte)'S', (byte)'E' };
            this.myMessage_10MB            = RandomDataGenerator.GetBytes(10000000);
        }
示例#5
0
        static void Main(string[] args)
        {
            SqlDependency.Start(connectionString);
            // Communicate using WebSockets.
            IMessagingSystemFactory aMessaging     = new WebSocketMessagingSystemFactory();
            IDuplexInputChannel     anInputChannel =
                aMessaging.CreateDuplexInputChannel("ws://127.0.0.1:8000/RealTimeChartWeb/");

            anInputChannel.ResponseReceiverConnected += (x, y) =>
            {
                Console.WriteLine("Connected client: " + y.ResponseReceiverId);
            };
            anInputChannel.ResponseReceiverDisconnected += (x, y) =>
            {
                Console.WriteLine("Disconnected client: " + y.ResponseReceiverId);
            };

            // Attach input channel and start listeing.
            aBroker.AttachDuplexInputChannel(anInputChannel);

            // Start working thread monitoring the CPU usage.
            bool   aStopWorkingThreadFlag = false;
            Thread aWorkingThread         = new Thread(() =>
            {
                float usage = 0;
                while (!aStopWorkingThreadFlag)
                {
                    getData(ref _refDate, aSerializer, aBroker);
                    Thread.Sleep(100);
                }
            });

            aWorkingThread.Start();

            Console.WriteLine("RealTimeChartWeb is running press ENTER to stop.");
            Console.ReadLine();

            // Wait until the working thread stops.
            aStopWorkingThreadFlag = true;
            aWorkingThread.Join(3000);

            aBroker.DetachDuplexInputChannel();
            SqlDependency.Stop(connectionString);
            // Detach the input channel and stop listening.
        }
示例#6
0
        public void MaxAmountOfConnections()
        {
            IMessagingSystemFactory aMessaging = new WebSocketMessagingSystemFactory()
            {
                MaxAmountOfConnections = 2
            };
            IDuplexOutputChannel anOutputChannel1 = aMessaging.CreateDuplexOutputChannel("ws://127.0.0.1:8049/");
            IDuplexOutputChannel anOutputChannel2 = aMessaging.CreateDuplexOutputChannel("ws://127.0.0.1:8049/");
            IDuplexOutputChannel anOutputChannel3 = aMessaging.CreateDuplexOutputChannel("ws://127.0.0.1:8049/");
            IDuplexInputChannel  anInputChannel   = aMessaging.CreateDuplexInputChannel("ws://127.0.0.1:8049/");

            try
            {
                ManualResetEvent aConnectionClosed = new ManualResetEvent(false);
                anOutputChannel3.ConnectionClosed += (x, y) =>
                {
                    EneterTrace.Info("Connection closed.");
                    aConnectionClosed.Set();
                };


                anInputChannel.StartListening();
                anOutputChannel1.OpenConnection();
                anOutputChannel2.OpenConnection();

                Assert.IsTrue(anOutputChannel1.IsConnected);
                Assert.IsTrue(anOutputChannel2.IsConnected);

                Assert.Throws <IOException>(() => anOutputChannel3.OpenConnection());

                if (!aConnectionClosed.WaitOne(1000))
                {
                    Assert.Fail("Third connection was not closed.");
                }
            }
            finally
            {
                anOutputChannel1.CloseConnection();
                anOutputChannel2.CloseConnection();
                anOutputChannel3.CloseConnection();
                anInputChannel.StopListening();
            }
        }
示例#7
0
        public void ConnectionTimeout()
        {
            IMessagingSystemFactory aMessaging = new WebSocketMessagingSystemFactory()
            {
                ConnectTimeout = TimeSpan.FromMilliseconds(1000)
            };

            // Nobody is listening on this address.
            IDuplexOutputChannel anOutputChannel = aMessaging.CreateDuplexOutputChannel("ws://109.74.151.135:8045/");

            ManualResetEvent aConnectionCompleted = new ManualResetEvent(false);

            try
            {
                // Start opening in another thread to be able to measure
                // if the timeout occured with the specified time.
                Exception anException = null;
                ThreadPool.QueueUserWorkItem(x =>
                {
                    try
                    {
                        anOutputChannel.OpenConnection();
                    }
                    catch (Exception err)
                    {
                        anException = err;
                    }
                    aConnectionCompleted.Set();
                });

                if (aConnectionCompleted.WaitOne(1500))
                {
                }

                Assert.AreEqual(typeof(TimeoutException), anException);
            }
            finally
            {
                anOutputChannel.CloseConnection();
            }
        }
示例#8
0
        public void Setup()
        {
            //EneterTrace.DetailLevel = EneterTrace.EDetailLevel.Debug;
            //EneterTrace.TraceLog = new StreamWriter("d:/tracefile.txt");

            // Generate random number for the port.
            int aPort = RandomPortGenerator.GenerateInt();

            IMessagingSystemFactory anUnderlyingMessaging = new WebSocketMessagingSystemFactory();

            IDuplexInputChannel aMessageBusServiceInputChannel = anUnderlyingMessaging.CreateDuplexInputChannel("ws://[::1]:" + aPort + "/Clients/");
            IDuplexInputChannel aMessageBusClientInputChannel  = anUnderlyingMessaging.CreateDuplexInputChannel("ws://[::1]:" + (aPort + 10) + "/Services/");

            myMessageBus = new MessageBusFactory().CreateMessageBus();
            myMessageBus.AttachDuplexInputChannels(aMessageBusServiceInputChannel, aMessageBusClientInputChannel);

            MessagingSystemFactory = new MessageBusMessagingFactory("ws://[::1]:" + aPort + "/Clients/", "ws://[::1]:" + (aPort + 10) + "/Services/", anUnderlyingMessaging)
            {
                ConnectTimeout = TimeSpan.FromMilliseconds(3000)
            };

            // Address of the service in the message bus.
            ChannelId = "Service1_Address";
        }
        public void OpenServer()
        {
            IsClose = true;
            IsOpen = false;
            _receiver = _receiverFactory.Value.CreateDuplexTypedMessageReceiver<ChatMessage, ChatMessage>();
            _receiver.MessageReceived += OnMessageReceived;

            _receiver.ResponseReceiverConnected += OnClientConnected;
            _receiver.ResponseReceiverDisconnected += OnClientDisconnected;

            // Use webSocket for the communication
            IMessagingSystemFactory messaging = new WebSocketMessagingSystemFactory();

            // Attach input channel and be able to receive request messages and send back response messages.
            IDuplexInputChannel inputChannel = messaging.CreateDuplexInputChannel("ws://192.168.15.124:8091/");
            _receiver.AttachDuplexInputChannel(inputChannel);
        }