标签:agg runas soft switch utf8 ext listener pip pipeline
using System; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using SuperSocket; using SuperSocket.ProtoBase; namespace myApp { class Program { static async Task Main(string[] args) { var host = SuperSocketHostBuilder .Create<StringPackageInfo, CommandLinePipelineFilter>() .ConfigurePackageHandler(async (session, package) => { var result = 0; try { switch (package.Key.ToUpper()) { case ("ADD"): result = package.Parameters .Select(p => int.Parse(p)) .Sum(); break; case ("SUB"): result = package.Parameters .Select(p => int.Parse(p)) .Aggregate((x, y) => x - y); break; case ("MULT"): result = package.Parameters .Select(p => int.Parse(p)) .Aggregate((x, y) => x * y); break; } } catch (Exception ex) { } await session.SendAsync(Encoding.UTF8.GetBytes(result.ToString() + "\r\n")); }) .ConfigureLogging((hostCtx, loggingBuilder) => { loggingBuilder.AddConsole(); }) .ConfigureSuperSocket(options => { options.Name = "Echo Server"; options.Listeners = new[] { new ListenOptions { Ip = "Any", Port = 4040 } }; }).Build(); await host.RunAsync(); } } }
参考资料:https://docs.supersocket.net/v2-0/zh-CN/A-Telnet-Example
标签:agg runas soft switch utf8 ext listener pip pipeline
原文地址:https://www.cnblogs.com/hellowzl/p/14442360.html