本文整理汇总了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();
});
}
示例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);
}
示例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);
}
示例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();
}