当前位置: 首页>>代码示例>>C#>>正文


C# Server.WaitAccept方法代码示例

本文整理汇总了C#中Server.WaitAccept方法的典型用法代码示例。如果您正苦于以下问题:C# Server.WaitAccept方法的具体用法?C# Server.WaitAccept怎么用?C# Server.WaitAccept使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Server的用法示例。


在下文中一共展示了Server.WaitAccept方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Outgoing_TCP_stream_must_be_able_to_write_a_sequence_of_ByteStrings

        public void Outgoing_TCP_stream_must_be_able_to_write_a_sequence_of_ByteStrings()
        {
            var server = new Server(this);
            var testInput = Enumerable.Range(0, 256).Select(i => ByteString.Create(new[] {Convert.ToByte(i)}));
            var expectedOutput = ByteString.Create(Enumerable.Range(0, 256).Select(Convert.ToByte).ToArray());

            Source.From(testInput)
                .Via(Sys.TcpStream().OutgoingConnection(server.Address))
                .To(Sink.Ignore<ByteString>())
                .Run(Materializer);

            var serverConnection = server.WaitAccept();
            serverConnection.Read(256);
            serverConnection.WaitRead().ShouldBeEquivalentTo(expectedOutput);
        }
开发者ID:rogeralsing,项目名称:akka.net,代码行数:15,代码来源:TcpSpec.cs

示例2: Outgoing_TCP_stream_must_be_able_to_read_a_sequence_of_ByteStrings

        public void Outgoing_TCP_stream_must_be_able_to_read_a_sequence_of_ByteStrings()
        {
            var server = new Server(this);
            var testInput = Enumerable.Range(0, 255).Select(i => ByteString.Create(new[] { Convert.ToByte(i) }));
            var expectedOutput = ByteString.Create(Enumerable.Range(0, 255).Select(Convert.ToByte).ToArray());

            var idle = new TcpWriteProbe(this); //Just register an idle upstream
            var resultFuture =
                Source.FromPublisher(idle.PublisherProbe)
                    .Via(Sys.TcpStream().OutgoingConnection(server.Address))
                    .RunAggregate(ByteString.Empty, (acc, input) => acc + input, Materializer);
            var serverConnection = server.WaitAccept();

            foreach (var input in testInput)
                serverConnection.Write(input);

            serverConnection.ConfirmedClose();
            resultFuture.Wait(TimeSpan.FromSeconds(3)).Should().BeTrue();
            resultFuture.Result.ShouldBeEquivalentTo(expectedOutput);
        }
开发者ID:rogeralsing,项目名称:akka.net,代码行数:20,代码来源:TcpSpec.cs

示例3: Outgoing_TCP_stream_must_work_in_the_happy_case

        public void Outgoing_TCP_stream_must_work_in_the_happy_case()
        {
            this.AssertAllStagesStopped(() =>
            {
                var testData = ByteString.Create(new byte[] {1, 2, 3, 4, 5});

                var server = new Server(this);

                var tcpReadProbe = new TcpReadProbe(this);
                var tcpWriteProbe = new TcpWriteProbe(this);
                Source.FromPublisher(tcpWriteProbe.PublisherProbe)
                    .Via(Sys.TcpStream().OutgoingConnection(server.Address))
                    .To(Sink.FromSubscriber(tcpReadProbe.SubscriberProbe))
                    .Run(Materializer);
                var serverConnection = server.WaitAccept();

                ValidateServerClientCommunication(testData, serverConnection, tcpReadProbe, tcpWriteProbe);

                tcpWriteProbe.Close();
                tcpReadProbe.Close();
                server.Close();
            }, Materializer);
        }
开发者ID:rogeralsing,项目名称:akka.net,代码行数:23,代码来源:TcpSpec.cs

示例4: Outgoing_TCP_stream_must_work_when_client_closes_write_then_remote_closes_write

        public void Outgoing_TCP_stream_must_work_when_client_closes_write_then_remote_closes_write()
        {
            this.AssertAllStagesStopped(() =>
            {
                var testData = ByteString.Create(new byte[] { 1, 2, 3, 4, 5 });
                var server = new Server(this);

                var tcpWriteProbe = new TcpWriteProbe(this);
                var tcpReadProbe = new TcpReadProbe(this);
                Source.FromPublisher(tcpWriteProbe.PublisherProbe)
                    .Via(Sys.TcpStream().OutgoingConnection(server.Address))
                    .To(Sink.FromSubscriber(tcpReadProbe.SubscriberProbe))
                    .Run(Materializer);
                var serverConnection = server.WaitAccept();

                // Client can still write
                tcpWriteProbe.Write(testData);
                serverConnection.Read(5);
                serverConnection.WaitRead().ShouldBeEquivalentTo(testData);

                // Close client side write
                tcpWriteProbe.Close();
                serverConnection.ExpectClosed(Akka.IO.Tcp.PeerClosed.Instance);

                // Server can still write
                serverConnection.Write(testData);
                tcpReadProbe.Read(5).ShouldBeEquivalentTo(testData);

                // Close server side write
                serverConnection.ConfirmedClose();
                tcpReadProbe.SubscriberProbe.ExpectComplete();

                serverConnection.ExpectClosed(Akka.IO.Tcp.ConfirmedClosed.Instance);
                serverConnection.ExpectTerminated();
            }, Materializer);
        }
开发者ID:rogeralsing,项目名称:akka.net,代码行数:36,代码来源:TcpSpec.cs

示例5: Outgoing_TCP_stream_must_materialize_correctly_when_used_in_multiple_flows

        public void Outgoing_TCP_stream_must_materialize_correctly_when_used_in_multiple_flows()
        {
            var testData = ByteString.Create(new byte[] { 1, 2, 3, 4, 5 });
            var server = new Server(this);

            var tcpWriteProbe1 = new TcpWriteProbe(this);
            var tcpReadProbe1 = new TcpReadProbe(this);
            var tcpWriteProbe2 = new TcpWriteProbe(this);
            var tcpReadProbe2 = new TcpReadProbe(this);
            var outgoingConnection = new Tcp().CreateExtension(Sys as ExtendedActorSystem).OutgoingConnection(server.Address);

            var conn1F = Source.FromPublisher(tcpWriteProbe1.PublisherProbe)
                    .ViaMaterialized(outgoingConnection, Keep.Both)
                    .To(Sink.FromSubscriber(tcpReadProbe1.SubscriberProbe))
                    .Run(Materializer).Item2;
            var serverConnection1 = server.WaitAccept();
            var conn2F = Source.FromPublisher(tcpWriteProbe2.PublisherProbe)
                    .ViaMaterialized(outgoingConnection, Keep.Both)
                    .To(Sink.FromSubscriber(tcpReadProbe2.SubscriberProbe))
                    .Run(Materializer).Item2;
            var serverConnection2 = server.WaitAccept();

            ValidateServerClientCommunication(testData, serverConnection1, tcpReadProbe1, tcpWriteProbe1);
            ValidateServerClientCommunication(testData, serverConnection2, tcpReadProbe2, tcpWriteProbe2);

            conn1F.Wait(TimeSpan.FromSeconds(1)).Should().BeTrue();
            conn2F.Wait(TimeSpan.FromSeconds(1)).Should().BeTrue();
            var conn1 = conn1F.Result;
            var conn2 = conn2F.Result;

            // Since we have already communicated over the connections we can have short timeouts for the tasks
            ((IPEndPoint) conn1.RemoteAddress).Port.Should().Be(((IPEndPoint) server.Address).Port);
            ((IPEndPoint) conn2.RemoteAddress).Port.Should().Be(((IPEndPoint) server.Address).Port);
            ((IPEndPoint) conn1.LocalAddress).Port.Should().NotBe(((IPEndPoint) conn2.LocalAddress).Port);

            tcpWriteProbe1.Close();
            tcpReadProbe1.Close();

            server.Close();
        }
开发者ID:rogeralsing,项目名称:akka.net,代码行数:40,代码来源:TcpSpec.cs

示例6: Outgoing_TCP_stream_must_shut_down_both_streams_when_connection_is_aborted_remotely

        public void Outgoing_TCP_stream_must_shut_down_both_streams_when_connection_is_aborted_remotely()
        {
            this.AssertAllStagesStopped(() =>
            {
                // Client gets a PeerClosed event and does not know that the write side is also closed
                var server = new Server(this);

                var tcpWriteProbe = new TcpWriteProbe(this);
                var tcpReadProbe = new TcpReadProbe(this);

                Source.FromPublisher(tcpWriteProbe.PublisherProbe)
                    .Via(Sys.TcpStream().OutgoingConnection(server.Address))
                    .To(Sink.FromSubscriber(tcpReadProbe.SubscriberProbe))
                    .Run(Materializer);
                var serverConnection = server.WaitAccept();

                serverConnection.Abort();
                tcpReadProbe.SubscriberProbe.ExpectSubscriptionAndError();
                tcpWriteProbe.TcpWriteSubscription.Value.ExpectCancellation();

                serverConnection.ExpectTerminated();
            }, Materializer);
        }
开发者ID:rogeralsing,项目名称:akka.net,代码行数:23,代码来源:TcpSpec.cs

示例7: Outgoing_TCP_stream_must_shut_everything_down_if_client_signals_error_after_remote_has_closed_write

        public void Outgoing_TCP_stream_must_shut_everything_down_if_client_signals_error_after_remote_has_closed_write()
        {
            this.AssertAllStagesStopped(() =>
            {
                var testData = ByteString.Create(new byte[] { 1, 2, 3, 4, 5 });
                var server = new Server(this);

                var tcpWriteProbe = new TcpWriteProbe(this);
                var tcpReadProbe = new TcpReadProbe(this);
                Source.FromPublisher(tcpWriteProbe.PublisherProbe)
                    .Via(Sys.TcpStream().OutgoingConnection(server.Address))
                    .To(Sink.FromSubscriber(tcpReadProbe.SubscriberProbe))
                    .Run(Materializer);
                var serverConnection = server.WaitAccept();

                // Server can still write
                serverConnection.Write(testData);
                tcpReadProbe.Read(5).ShouldBeEquivalentTo(testData);

                // Close remote side write
                serverConnection.ConfirmedClose();
                tcpReadProbe.SubscriberProbe.ExpectComplete();

                // Client can still write
                tcpWriteProbe.Write(testData);
                serverConnection.Read(5);
                serverConnection.WaitRead().ShouldBeEquivalentTo(testData);
                
                tcpWriteProbe.TcpWriteSubscription.Value.SendError(new IllegalStateException("test"));
                serverConnection.ExpectClosed(c => c.IsErrorClosed);
                serverConnection.ExpectTerminated();
            }, Materializer);
        }
开发者ID:rogeralsing,项目名称:akka.net,代码行数:33,代码来源:TcpSpec.cs

示例8: Outgoing_TCP_stream_must_work_when_client_closes_read_then_client_closes_write

        public void Outgoing_TCP_stream_must_work_when_client_closes_read_then_client_closes_write()
        {
            this.AssertAllStagesStopped(() =>
            {
                var testData = ByteString.Create(new byte[] { 1, 2, 3, 4, 5 });
                var server = new Server(this);

                var tcpWriteProbe = new TcpWriteProbe(this);
                var tcpReadProbe = new TcpReadProbe(this);
                Source.FromPublisher(tcpWriteProbe.PublisherProbe)
                    .Via(Sys.TcpStream().OutgoingConnection(server.Address))
                    .To(Sink.FromSubscriber(tcpReadProbe.SubscriberProbe))
                    .Run(Materializer);
                var serverConnection = server.WaitAccept();

                // Server can still write
                serverConnection.Write(testData);
                tcpReadProbe.Read(5).ShouldBeEquivalentTo(testData);

                // Close client side read
                tcpReadProbe.TcpReadSubscription.Value.Cancel();

                // Client can still write
                tcpWriteProbe.Write(testData);
                serverConnection.Read(5);
                serverConnection.WaitRead().ShouldBeEquivalentTo(testData);

                // Close client side write
                tcpWriteProbe.Close();

                // Need a write on the server side to detect the close event
                AwaitAssert(() =>
                {
                    serverConnection.Write(testData);
                    serverConnection.ExpectClosed(c=>c.IsErrorClosed, TimeSpan.FromMilliseconds(500));
                }, TimeSpan.FromSeconds(5));

                serverConnection.ExpectTerminated();
            }, Materializer);
        }
开发者ID:rogeralsing,项目名称:akka.net,代码行数:40,代码来源:TcpSpec.cs


注:本文中的Server.WaitAccept方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。