mirror of
https://github.com/Azure/DotNetty.git
synced 2026-10-20 07:37:46 +08:00
4f28a55b48
Motivation .NET Core tooling allows building for both .NET Framework and .NET Standard while easing pains of running tests and packaging. Modifications - csproj -> xproj + project.json - support for .NET Standard 1.3 - build script is now based on CAKE - using dotnet CLI for building, testing, packing - strong name by default (snk included) Result DotNetty works on .NET Core and any other platform supporting .NET Standard 1.3+.
63 lines
2.3 KiB
C#
63 lines
2.3 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
namespace Discard.Server
|
|
{
|
|
using System;
|
|
using System.IO;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using System.Threading.Tasks;
|
|
using DotNetty.Handlers.Logging;
|
|
using DotNetty.Handlers.Tls;
|
|
using DotNetty.Transport.Bootstrapping;
|
|
using DotNetty.Transport.Channels;
|
|
using DotNetty.Transport.Channels.Sockets;
|
|
using Examples.Common;
|
|
|
|
class Program
|
|
{
|
|
static async Task RunServerAsync()
|
|
{
|
|
ExampleHelper.SetConsoleLogger();
|
|
|
|
var bossGroup = new MultithreadEventLoopGroup(1);
|
|
var workerGroup = new MultithreadEventLoopGroup();
|
|
X509Certificate2 tlsCertificate = null;
|
|
if (ServerSettings.IsSsl)
|
|
{
|
|
tlsCertificate = new X509Certificate2(Path.Combine(ExampleHelper.ProcessDirectory, "shared\\dotnetty.com.pfx"), "password");
|
|
}
|
|
try
|
|
{
|
|
var bootstrap = new ServerBootstrap();
|
|
bootstrap
|
|
.Group(bossGroup, workerGroup)
|
|
.Channel<TcpServerSocketChannel>()
|
|
.Option(ChannelOption.SoBacklog, 100)
|
|
.Handler(new LoggingHandler("LSTN"))
|
|
.ChildHandler(new ActionChannelInitializer<ISocketChannel>(channel =>
|
|
{
|
|
IChannelPipeline pipeline = channel.Pipeline;
|
|
if (tlsCertificate != null)
|
|
{
|
|
pipeline.AddLast(TlsHandler.Server(tlsCertificate));
|
|
}
|
|
pipeline.AddLast(new LoggingHandler("CONN"));
|
|
pipeline.AddLast(new DiscardServerHandler());
|
|
}));
|
|
|
|
IChannel bootstrapChannel = await bootstrap.BindAsync(ServerSettings.Port);
|
|
|
|
Console.ReadLine();
|
|
|
|
await bootstrapChannel.CloseAsync();
|
|
}
|
|
finally
|
|
{
|
|
Task.WaitAll(bossGroup.ShutdownGracefullyAsync(), workerGroup.ShutdownGracefullyAsync());
|
|
}
|
|
}
|
|
|
|
public static void Main() => RunServerAsync().Wait();
|
|
}
|
|
} |