// 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, "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();}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。