Example #1
0
        public void Client_should_connect_to_server_and_signal_appropriate_callbacks()
        {
            var connected1 = new ManualResetEventSlim(false);
            var connected2 = new ManualResetEventSlim(false);

            var ex = ServerHelpers.CreateExecutor();
            var server = ServerHelpers.CreateServer();

            server.Connected.Subscribe(client =>
                {
                    connected1.Set();
                });

            server.Started.Subscribe(u =>
            {
                var client = new SocketClient(ex);
                client.Connected.Subscribe( _ =>
                    {
                        connected2.Set();
                    });
                client.Disconnected.Subscribe(exn =>
                    {
                        throw exn;
                    });
                client.Connect(new IPEndPoint(IPAddress.Loopback, server.BindEndPoint.Port));
            });

            server.Start();

            connected1.AssertWaitFor(5000);
            connected2.AssertWaitFor(5000);

            server.StopAndAssertStopped();
        }
Example #2
0
 private void ClientConnected(SocketClient client)
 {
     this.client = new MessageClient(
                     new FramedClient(client),
                     new ProtoBufStacksSerializer(),
                     new ServerMessageHandler(service));
 }
Example #3
0
        private void ClientConnected(SocketClient client)
        {
            this.client = new MessageClient(
                            new FramedClient(client),
                            new ProtoBufStacksSerializer(),
                            new ServerMessageHandler(service));

            this.client.PreLoadTypesFromAssemblyOfType<TemperatureChanged>();
        }
Example #4
0
        public void Client_should_receive_disconnected_event_with_timeout_after_period_of_time()
        {
            var client = new SocketClient();
            var connected = client.Connect("tcp://10.255.255.1:80");


            try
            {
                connected.Wait();
            }
            catch (SocketException exn)
            {
                Assert.Equal(SocketError.TimedOut, exn.SocketErrorCode);
            }
        }
Example #5
0
        public void Calling_connect_twice_should_throw_an_exception()
        {
            var hasConnected = new ManualResetEventSlim();
            var executor = ServerHelpers.CreateExecutor();
            var server = ServerHelpers.CreateServer(executor);

            server.Started.Subscribe(_ =>
            {
                Assert.Throws(typeof(InvalidOperationException),
                    () =>
                    {
                        var client = new SocketClient(executor);
                        client.Connect(server.BindEndPoint);
                        hasConnected.Set();
                        client.Connect(server.BindEndPoint);
                    });
            });

            server.Start();

            hasConnected.AssertWaitFor();
        }
Example #6
0
        public static void CreateServerAndConnectedClient(out SocketServer server,
            out SocketClient client1, out SocketClient client2)
        {
            var connected1 = new ManualResetEventSlim(false);
            var connected2 = new ManualResetEventSlim(false);

            var ex = ServerHelpers.CreateExecutor();
            var s = ServerHelpers.CreateServer();

            SocketClient lClient = null;
            SocketClient sClient = null;

            s.Connected.Subscribe(c =>
            {
                sClient = c;
                connected2.Set();
            });

            s.Started.Subscribe(_ =>
            {
                var c = new SocketClient(ex);
                c.Connected.Subscribe(u =>
                {
                    lClient = c;
                    connected1.Set();
                });
                c.Connect(new IPEndPoint(IPAddress.Loopback, s.BindEndPoint.Port));
            });

            s.Start();

            connected1.AssertWaitFor(3000);
            connected2.AssertWaitFor(3000);

            server = s;
            client1 = lClient;
            client2 = sClient;
        }
Example #7
0
 private void OnConnected(SocketClient client)
 {
     executor.Enqueue(() =>
         {
             this.connected.OnNext(client);
         });
 }
Example #8
0
        public void If_client_cannot_connect_if_should_raise_disconnect_event_with_connection_refused_error()
        {
            var disconnectedCalled = new ManualResetEventSlim();

            var executor = ServerHelpers.CreateExecutor();
            var client = new SocketClient(executor);

            client.Disconnected.Subscribe(exn =>
                {
                    Assert.IsType(typeof(SocketException), exn);
                    Assert.Equal((int)SocketError.ConnectionRefused, ((SocketException)exn).ErrorCode);
                    disconnectedCalled.Set();
                });

            client.Connect(new IPEndPoint(IPAddress.Loopback, 45232));
            disconnectedCalled.AssertWaitFor();
        }
Example #9
0
 private void OnConnected(SocketClient client)
 {
     var h = Connected;
     if (h != null)
     {
         executor.Enqueue(() => h(client));
     }
 }