本文整理汇总了C#中Server.Shutdown方法的典型用法代码示例。如果您正苦于以下问题:C# Server.Shutdown方法的具体用法?C# Server.Shutdown怎么用?C# Server.Shutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server
的用法示例。
在下文中一共展示了Server.Shutdown方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestClientServer
public void TestClientServer()
{
SecureRandom secureRandom = new SecureRandom();
DtlsClientProtocol clientProtocol = new DtlsClientProtocol(secureRandom);
DtlsServerProtocol serverProtocol = new DtlsServerProtocol(secureRandom);
MockDatagramAssociation network = new MockDatagramAssociation(1500);
Server server = new Server(serverProtocol, network.Server);
Thread serverThread = new Thread(new ThreadStart(server.Run));
serverThread.Start();
DatagramTransport clientTransport = network.Client;
clientTransport = new UnreliableDatagramTransport(clientTransport, secureRandom, 0, 0);
clientTransport = new LoggingDatagramTransport(clientTransport, Console.Out);
MockDtlsClient client = new MockDtlsClient(null);
DtlsTransport dtlsClient = clientProtocol.Connect(client, clientTransport);
for (int i = 1; i <= 10; ++i)
{
byte[] data = new byte[i];
Arrays.Fill(data, (byte)i);
dtlsClient.Send(data, 0, data.Length);
}
byte[] buf = new byte[dtlsClient.GetReceiveLimit()];
while (dtlsClient.Receive(buf, 0, buf.Length, 100) >= 0)
{
}
dtlsClient.Close();
server.Shutdown(serverThread);
}
示例2: RunTest
public void RunTest(TlsTestConfig config)
{
CheckDtlsVersion(config.clientMinimumVersion);
CheckDtlsVersion(config.clientOfferVersion);
CheckDtlsVersion(config.serverMaximumVersion);
CheckDtlsVersion(config.serverMinimumVersion);
SecureRandom secureRandom = new SecureRandom();
DtlsClientProtocol clientProtocol = new DtlsClientProtocol(secureRandom);
DtlsServerProtocol serverProtocol = new DtlsServerProtocol(secureRandom);
MockDatagramAssociation network = new MockDatagramAssociation(1500);
TlsTestClientImpl clientImpl = new TlsTestClientImpl(config);
TlsTestServerImpl serverImpl = new TlsTestServerImpl(config);
Server server = new Server(this, serverProtocol, network.Server, serverImpl);
Thread serverThread = new Thread(new ThreadStart(server.Run));
serverThread.Start();
Exception caught = null;
try
{
DatagramTransport clientTransport = network.Client;
if (TlsTestConfig.DEBUG)
{
clientTransport = new LoggingDatagramTransport(clientTransport, Console.Out);
}
DtlsTransport dtlsClient = clientProtocol.Connect(clientImpl, clientTransport);
for (int i = 1; i <= 10; ++i)
{
byte[] data = new byte[i];
Arrays.Fill(data, (byte)i);
dtlsClient.Send(data, 0, data.Length);
}
byte[] buf = new byte[dtlsClient.GetReceiveLimit()];
while (dtlsClient.Receive(buf, 0, buf.Length, 100) >= 0)
{
}
dtlsClient.Close();
}
catch (Exception e)
{
caught = e;
LogException(caught);
}
server.Shutdown(serverThread);
// TODO Add checks that the various streams were closed
Assert.AreEqual(config.expectFatalAlertConnectionEnd, clientImpl.FirstFatalAlertConnectionEnd, "Client fatal alert connection end");
Assert.AreEqual(config.expectFatalAlertConnectionEnd, serverImpl.FirstFatalAlertConnectionEnd, "Server fatal alert connection end");
Assert.AreEqual(config.expectFatalAlertDescription, clientImpl.FirstFatalAlertDescription, "Client fatal alert description");
Assert.AreEqual(config.expectFatalAlertDescription, serverImpl.FirstFatalAlertDescription, "Server fatal alert description");
if (config.expectFatalAlertConnectionEnd == -1)
{
Assert.IsNull(caught, "Unexpected client exception");
Assert.IsNull(server.mCaught, "Unexpected server exception");
}
}
示例3: ServerThread
/// <summary>
/// Worker thread for the server.
/// </summary>
void ServerThread()
{
// Create the server
_server = new Server();
_server.ConsoleCommandExecuted += Server_ConsoleCommandExecuted;
// Check if a shutdown request was made before the server even got a chance to finish being constructed
if (_shutdownRequested)
_server.Shutdown();
// Start the main loop (the thread will block here until the server is closed)
_server.Start();
// No longer blocking, so the server loop has terminated
_serverDisposed = true;
// Close the form when the server stops
try
{
// Do not call close if we are already closing
if (!Disposing && !IsDisposed)
Invoke(new EventHandler(delegate { Close(); }));
}
catch (InvalidOperationException ex)
{
const string errmsg = "Error occured while trying to shut down the server. Exception: {0}";
if (log.IsErrorEnabled)
log.ErrorFormat(errmsg, ex);
Debug.Fail(string.Format(errmsg, ex));
}
}