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


C# Server.Close方法代码示例

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


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

示例1: ServerWillCloseSocket

        public void ServerWillCloseSocket()
        {
            var server = new Server();
            server.Listen(56566, null, null);
            server.Close();

            Assert.Throws<SocketException>(() =>
                              {
                                  var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
                                  socket.Connect("localhost", 56566);
                                  socket.Close();
                              });
        }
开发者ID:virajs,项目名称:firefly,代码行数:13,代码来源:ServerTests.cs

示例2: ServerWillEmitCloseRequest

        public void ServerWillEmitCloseRequest()
        {
            var server = new Server();
            var closed = false;
            server.OnClose(errno => closed = true);
            server.Listen(56566, null, null);

            var closedBefore = closed;
            server.Close();
            var closedAfter = closed;

            Assert.Equal(false, closedBefore);
            Assert.Equal(true, closedAfter);
        }
开发者ID:virajs,项目名称:firefly,代码行数:14,代码来源:ServerTests.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_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


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