public async void Start() { bossGroup = new MultithreadEventLoopGroup(1); workerGroup = new MultithreadEventLoopGroup(); try { var bootstrap = new ServerBootstrap(); bootstrap .Group(bossGroup, workerGroup) .Channel <TcpServerSocketChannel>() .Option(ChannelOption.SoBacklog, 100) .Handler(new LoggingHandler(LogLevel.INFO)) .ChildHandler(new ActionChannelInitializer <ISocketChannel>(channel => { IChannelPipeline pipeline = channel.Pipeline; pipeline.AddLast(new DelimiterBasedFrameDecoder(133680, Delimiters.LineDelimiter())); pipeline.AddLast(STRING_ENCODER, STRING_DECODER, new UpdaterServerHandler()); })); bootstrapChannel = await bootstrap.BindAsync(9527); Console.WriteLine("服务已启动..."); LoggerHelper.Info("服务已启动..."); } catch (Exception ex) { Console.WriteLine("服务启动异常:{0}", ex.StackTrace); LoggerHelper.Error("服务启动异常", ex); } }
static async Task RunServerAsync(int port) { var bossGroup = new MultithreadEventLoopGroup(1); var workerGroup = new MultithreadEventLoopGroup(); var stringEncoder = new StringEncoder(); var stringDecoder = new StringDecoder(); var serverHandler = new ServerHandler(GameCore); try { var bootstrap = new ServerBootstrap(); bootstrap .Group(bossGroup, workerGroup) .Channel <TcpServerSocketChannel>() .Option(ChannelOption.SoBacklog, 100) .Handler(new LoggingHandler(LogLevel.INFO)) .ChildHandler(new ActionChannelInitializer <ISocketChannel>(channel => { var pipeline = channel.Pipeline; pipeline.AddLast(new DelimiterBasedFrameDecoder(8192, Delimiters.LineDelimiter())); pipeline.AddLast(stringEncoder, stringDecoder, serverHandler); })); var bootstrapChannel = await bootstrap.BindAsync(port); GameCore.RunContainers(); await bootstrapChannel.CloseAsync(); } finally { Task.WaitAll(bossGroup.ShutdownGracefullyAsync(), workerGroup.ShutdownGracefullyAsync()); } }
static async Task RunClientAsync() { var group = new MultithreadEventLoopGroup(); try { var bootstrap = new Bootstrap(); bootstrap .Group(group) .Channel <TcpSocketChannel>() .Option(ChannelOption.TcpNodelay, true) .Handler(new ActionChannelInitializer <ISocketChannel>(channel => { IChannelPipeline pipeline = channel.Pipeline; pipeline.AddLast(new DelimiterBasedFrameDecoder(8192, Delimiters.LineDelimiter())); pipeline.AddLast(new StringEncoder(), new StringDecoder(), new ClientHandler()); })); IPAddress ip = IPAddress.Parse("127.0.0.1"); IChannel bootstrapChannel = await bootstrap.ConnectAsync(new IPEndPoint(ip, 4242)); for (; ;) { string line = Console.ReadLine(); if (string.IsNullOrEmpty(line)) { continue; } try { await bootstrapChannel.WriteAndFlushAsync(line + "\r\n"); } catch { Console.WriteLine("Deconnection..."); await bootstrapChannel.CloseAsync(); break; } if (string.Equals(line, "/leave", StringComparison.OrdinalIgnoreCase)) { await bootstrapChannel.CloseAsync(); break; } } await bootstrapChannel.CloseAsync(); } catch (Exception e) { Console.Error.WriteLine("Serveur introuvable"); } finally { group.ShutdownGracefullyAsync().Wait(1000); } }
List <string[]> SplitLines(string[] lines, string delimiter) { string regexPattern = Delimiters.GetSplitPattern(delimiter); var rows = lines.Select(line => Regex.Split(line, regexPattern)).ToList(); return(rows); }
public void ShouldAllowAddingNewSingleCharacterDelimiter(char input) { var delimiters = new Delimiters(new List <Delimiter>()); delimiters.Add(new Delimiter(input, false)); Assert.AreEqual(delimiters.NumOfDelimiters(), 1); }
/// <summary> /// Creates a VDF string which contains this node and its children (Keys and Nodes). /// </summary> /// <param name="delimiter">Indicates the delimiter to be appended after the name of the node, the curly brackets and the key-value pair.</param> /// <param name="TabLevel">Indicates how many tab characters should be appended at the beginning of the name of the node, the curly brackets and the key-value pair.</param> /// <returns></returns> public string ToString(Delimiters delimiter, int TabLevel = 0) { string strDelimiter = Helper.DelimiterEnumToString(delimiter); //Convert the selected delimiter to its String Value string tab = (TabLevel > 0) ? Helper.Tabify(TabLevel) : ""; //Append horizontal tab(s) at the beginning of our strings. StringBuilder sb = new StringBuilder(tab + "\"" + Helper.UnformatString(Name) + "\""); //Begin building our string by starting with the name of our VDFData sb.Append(strDelimiter + tab + "{" + strDelimiter); // Append the delimiter and then the '{' character which tells us that we are within the contents of the node and then another delimiter if (TabLevel >= 0) { ++TabLevel; //Make sure to increase the TabLevel if it isn't set to a negative number. } if (Keys != null) { foreach (VDFKey key in Keys) //Append all the keys under this node to the string { sb.Append(key.ToString(TabLevel) + strDelimiter); //Append the string value of the single key element. We must also make sure that the string returned has the correct amount of tabs at the beginning. } } if (Nodes != null) { foreach (VDFNode node in Nodes) //Append all the nodes under this node and their children to the string { sb.Append(node.ToString(delimiter, TabLevel) + strDelimiter); //We must make sure that the child nodes have the same styling as their parent node so pass on the delimiter and the tab level. } } sb.Append(tab + "}"); //Close off our node with '}'. Also, make sure that the correct number of tabs is appended before the closing curly brackets. return(sb.ToString()); }
static async Task RunServerAsync() { var bossGroup = new MultithreadEventLoopGroup(1); var workerGroup = new MultithreadEventLoopGroup(); var STRING_ENCODER = new StringEncoder(); var STRING_DECODER = new StringDecoder(); var SERVER_HANDLER = new ChatServerHandler(); try { var bootstrap = new ServerBootstrap(); bootstrap .Group(bossGroup, workerGroup) .Channel <TcpServerSocketChannel>() .Option(ChannelOption.SoBacklog, 100) .Handler(new LoggingHandler(LogLevel.INFO)) .ChildHandler(new ActionChannelInitializer <ISocketChannel>(channel => { IChannelPipeline pipeline = channel.Pipeline; pipeline.AddLast(new DelimiterBasedFrameDecoder(8192, Delimiters.LineDelimiter())); pipeline.AddLast(STRING_ENCODER, STRING_DECODER, SERVER_HANDLER); })); IChannel bootstrapChannel = await bootstrap.BindAsync(8080); Console.ReadLine(); await bootstrapChannel.CloseAsync(); } finally { Task.WaitAll(bossGroup.ShutdownGracefullyAsync(), workerGroup.ShutdownGracefullyAsync()); } }
//helper: undo the above Escape() effect and restores to its intended value, when an escaped string is retrieved. public string UnEscape(string escapedSectionValue) { StringBuilder buffer = new StringBuilder(); if (!string.IsNullOrEmpty(escapedSectionValue)) { char[] valueCharArray = escapedSectionValue.ToCharArray(); for (int i = 0; i < valueCharArray.Length; i++) { char curr = valueCharArray[i]; if (curr == EscapeChar && i < valueCharArray.Length - 1) { char next = valueCharArray[i + 1]; if (Delimiters.Contains(next) || next == EscapeChar) { continue; //skip the escape-char } } buffer.Append(curr); } } return buffer.ToString(); //un-escaped section value }
public async Task Connect(string serverAddress) { try { group = new MultithreadEventLoopGroup(); var bootstrap = new Bootstrap(); bootstrap .Group(group) .Channel <TcpSocketChannel>() .Option(ChannelOption.TcpNodelay, true) .Handler(new ActionChannelInitializer <ISocketChannel>(channel => { IChannelPipeline pipeline = channel.Pipeline; pipeline.AddLast(new DelimiterBasedFrameDecoder(133680, Delimiters.LineDelimiter())); pipeline.AddLast(new StringEncoder(), new StringDecoder(), ClientHandler); })); bootstrapChannel = await bootstrap.ConnectAsync(new IPEndPoint(IPAddress.Parse(serverAddress), 9527)); } catch { group.ShutdownGracefullyAsync().Wait(1000); } }
/// <summary> /// Gets the header as a string. /// </summary> /// <param name="fields">The fields to use in the header.</param> /// <param name="delimiters">The delimiters to use in the header.</param> /// <returns>Returns a delimited string of field names.</returns> protected string getHeader(string[] fields, Delimiters delimiters) { StringBuilder sb = new StringBuilder(); int counter = 1; foreach (string fieldName in fields) { string value = fieldName.Replace( delimiters.TextQualifier.ToString(), String.Format("{0}{1}", delimiters.EscapeCharacter, delimiters.TextQualifier) ); if (delimiters.TextQualifier != Delimiters.Null) { sb.Append(delimiters.TextQualifier); } sb.Append(value); if (delimiters.TextQualifier != Delimiters.Null) { sb.Append(delimiters.TextQualifier); } if (counter < fields.Length) { sb.Append(delimiters.FieldSeparator); } counter++; } return(sb.ToString()); }
DataTable ReadDataFromTextFileManually(ExtendedFile file) { DataTable table = new DataTable(file.Name); if (!FileTypes.isTextFile(file)) { return(table); } var lines = File.ReadAllLines(file.File.FullName); var delimiter = Delimiters.GetDelimiterByHeader(lines.First()); var fileRows = SplitLines(lines, delimiter); var columns = fileRows.First() .Where(x => !string.IsNullOrWhiteSpace(x)) .Select(x => new DataColumn(x.TrimQuotes())).ToArray(); table.Columns.AddRange(columns); foreach (var fileRow in fileRows.Skip(1)) { var updatedRow = fileRow.Where(x => !string.IsNullOrWhiteSpace(x)).ToArray(); if (columns.Length == updatedRow.Length) { var newTableRow = table.NewRow(); for (int i = 0; i < table.Columns.Count; i++) { newTableRow[i] = updatedRow[i].TrimQuotes(); } table.Rows.Add(newTableRow); } } return(table); }
static async Task RunClientAsync(string ip, int port) { var group = new MultithreadEventLoopGroup(); string targetHost = null; try { var bootstrap = new Bootstrap(); bootstrap .Group(group) .Channel <TcpSocketChannel>() .Option(ChannelOption.TcpNodelay, true) .Handler(new ActionChannelInitializer <ISocketChannel>(channel => { IChannelPipeline pipeline = channel.Pipeline; pipeline.AddLast(new DelimiterBasedFrameDecoder(8192, Delimiters.LineDelimiter())); pipeline.AddLast(new StringEncoder(), new StringDecoder(), handler); })); IChannel bootstrapChannel = await bootstrap.ConnectAsync(new IPEndPoint(IPAddress.Parse(ip), port)); for (;;) { Console.Write("$> "); var line = Console.ReadLine(); if (string.IsNullOrEmpty(line)) { continue; } try { var response = GameHandler.HandleClientCmd(handler.GetEventHandler(), line); if (response != null) { var serObj = SerializeHandler.SerializeObj(response); await bootstrapChannel.WriteAndFlushAsync(serObj + "\r\n"); } } catch (Exception e) { Console.Error.WriteLine(e.Message); } if (string.Equals(line, "bye", StringComparison.OrdinalIgnoreCase)) { await bootstrapChannel.CloseAsync(); break; } } await bootstrapChannel.CloseAsync(); } finally { group.ShutdownGracefullyAsync().Wait(1000); } }
public ImportViewModel(WizardViewModel wizardViewModel, List <string> lines) { Lines = lines; wizardViewModel.ContentWindow = this; wizardViewModel.WizardTitle = "Импорт из файла"; _wizardViewModel = wizardViewModel; ListItem semicolon = new ListItem("Точка с запятой ( ; )", ";"); Delimiters.Add(semicolon); ListItem verticalBar = new ListItem("Вертикальная черта ( | )", "|"); Delimiters.Add(verticalBar); ListItem tab = new ListItem("Табулятор ( t )", "\t"); Delimiters.Add(tab); ListItem comma = new ListItem("Запятая ( , )", ","); Delimiters.Add(comma); ListItem colon = new ListItem("Двоеточие ( : )", ":"); Delimiters.Add(colon); SelectedDelimiter = Delimiters[0]; SetData(); }
static async Task RunClientAsync() { var HOST = IPAddress.Parse("127.0.0.1"); var group = new MultithreadEventLoopGroup(); try { var bootstrap = new Bootstrap(); bootstrap .Group(group) .Channel <TcpSocketChannel>() .Option(ChannelOption.TcpNodelay, true) .Handler(new ActionChannelInitializer <ISocketChannel>(channel => { IChannelPipeline pipeline = channel.Pipeline; pipeline.AddLast(new DelimiterBasedFrameDecoder(8192, Delimiters.LineDelimiter())); pipeline.AddLast(new StringEncoder(), new StringDecoder(), new ChatClientHandler()); })); IChannel bootstrapChannel = await bootstrap.ConnectAsync(new IPEndPoint(HOST, 8080)); ProtocolJson pj = new ProtocolJson(); for (;;) { string line = Console.ReadLine(); pj.message = line; pj.messageDate = DateTime.Now; string Json = JsonConvert.SerializeObject(pj, Formatting.None); if (string.IsNullOrEmpty(line)) { continue; } try { await bootstrapChannel.WriteAndFlushAsync(Json + "\r\n"); //await bootstrapChannel.WriteAndFlushAsync(line + "\r\n"); } catch { } if (string.Equals(line, "bye", StringComparison.OrdinalIgnoreCase)) { await bootstrapChannel.CloseAsync(); break; } } await bootstrapChannel.CloseAsync(); } finally { group.ShutdownGracefullyAsync().Wait(1000); } }
void SkipDelimiters() { while (position < text.Length && Delimiters.IndexOf(text[position]) != -1) { ++position; } }
/// <summary> /// Initializes a new instance of <see cref="Separators"/>. /// </summary> /// <param name="delims">The <see cref="Delimiters"/> used to initialize the object.</param> public Separators(Delimiters delims) { this.FieldSeparator = delims.FieldSeparator; this.TextQualifier = delims.TextQualifier; this.NewRecord = delims.NewRecord; this.EscapeCharacter = delims.EscapeCharacter; this.FlattenedNewLine = delims.FlattenedNewLine; }
/// <summary> /// Saves VDF Data Structure to file. /// </summary> /// <param name="FilePath">Indicates the path to where the file will be saved.</param> /// <param name="delimiter">Indicates the delimiter to be appended after the name of the node, the curly brackets and the key-value pair.</param> /// <param name="StartingTabLevel">Indicates how many tab characters should be appended at the beginning of the name of the node, the curly brackets and the key-value pair.</param> /// <param name="Overwrite">If set to true and the file already exists, overwrite it. If set to false and the file exists already, the method will throw an error.</param> public void SaveToFile(string FilePath, Delimiters delimiter, int StartingTabLevel = 0, bool Overwrite = false) { if (!Overwrite && File.Exists(FilePath)) { throw new VDFStreamException("File " + FilePath + " already exists!"); } File.WriteAllText(FilePath, ToString(delimiter, StartingTabLevel)); }
public void BeforeAdderTests() { var delimiters = new List <Delimiter> { new Delimiter(',', false), new Delimiter('\n', false) }; delimiter = new Delimiters(delimiters); }
/// <summary> /// Tokenizes the given string into a list of tokens /// </summary> /// <param name="input">The string to tokenize</param> /// <returns>The list of tokens</returns> public List <T> Tokenize(string input) { List <T> tokens = new List <T>(); Token currentToken = null; insideStringLiteral = false; char currentCharacter; char?nextCharacter; int currentIndex = -1; int currentLine = 1; int currentColumn = 0; while (TryReadCharacter(input, ref currentIndex, out currentCharacter)) { char peeked; if (TryPeekCharacter(input, currentIndex, out peeked)) { nextCharacter = peeked; } else { nextCharacter = null; } currentColumn++; if (currentCharacter == '\n') { Tokenize_Whitespace(input, ref currentIndex, ref currentCharacter, ref currentLine, ref currentColumn, ref currentToken, tokens); currentLine++; currentColumn = 0; } else if (IsEscapeSequence(currentCharacter, nextCharacter)) { Tokenize_EscapeCharacter(input, ref currentIndex, ref currentCharacter, ref currentLine, ref currentColumn, ref currentToken, tokens); } else if (insideStringLiteral) { Tokenize_Plain(input, ref currentIndex, ref currentCharacter, ref currentLine, ref currentColumn, ref currentToken, tokens); } else if (Delimiters.Contains("" + currentCharacter)) { Tokenize_DelimiterCharacter(input, ref currentIndex, ref currentCharacter, ref currentLine, ref currentColumn, ref currentToken, tokens); } else if (char.IsWhiteSpace(currentCharacter)) { Tokenize_Whitespace(input, ref currentIndex, ref currentCharacter, ref currentLine, ref currentColumn, ref currentToken, tokens); } else { Tokenize_Plain(input, ref currentIndex, ref currentCharacter, ref currentLine, ref currentColumn, ref currentToken, tokens); } } FinalizeTokenIfNotNull(ref currentToken, tokens); return(tokens); }
public void Instructions_Job_DatImport() { // arrange FileInfo infile = new FileInfo("x:\\test\\testfile.dat"); Encoding encoding = Encoding.GetEncoding(1252); Delimiters delims = Delimiters.COMMA_DELIMITED; List <RepresentativeBuilder> linkedFiles = new List <RepresentativeBuilder>(); linkedFiles.Add(new RepresentativeBuilder("NativeLink", Representative.FileType.Native)); DatImport import = new DatImport(infile, encoding, delims, "DOCID"); import.HasHeader = true; import.ParentColumnName = "BEGATT"; import.ChildColumnName = "ATTIDS"; import.ChildColumnDelimiter = ";"; import.LinkedFiles = linkedFiles.Select(f => new RepresentativeInfo(f)).ToArray(); Job job = new Job(new Import[] { import }, null, null); // act string xml = job.ToXml(); Job testJob = Job.Deserialize(xml); // assert Assert.AreEqual(job.Imports[0].Encoding, testJob.Imports[0].Encoding); Assert.AreEqual(job.Imports[0].File.FullName, testJob.Imports[0].File.FullName); Assert.AreEqual( ((DatImport)job.Imports[0]).KeyColumnName, ((DatImport)testJob.Imports[0]).KeyColumnName ); Assert.AreEqual( ((DatImport)job.Imports[0]).ParentColumnName, ((DatImport)testJob.Imports[0]).ParentColumnName ); Assert.AreEqual( ((DatImport)job.Imports[0]).ChildColumnName, ((DatImport)testJob.Imports[0]).ChildColumnName ); Assert.AreEqual( ((DatImport)job.Imports[0]).ChildColumnDelimiter, ((DatImport)testJob.Imports[0]).ChildColumnDelimiter ); Assert.AreEqual( ((DatImport)job.Imports[0]).HasHeader, ((DatImport)testJob.Imports[0]).HasHeader ); for (int i = 0; i < ((DatImport)job.Imports[0]).LinkedFiles.Length; i++) { Assert.AreEqual( ((DatImport)job.Imports[0]).LinkedFiles[i].ColumnName, ((DatImport)testJob.Imports[0]).LinkedFiles[i].ColumnName ); Assert.AreEqual( ((DatImport)job.Imports[0]).LinkedFiles[i].FileType, ((DatImport)testJob.Imports[0]).LinkedFiles[i].FileType ); } }
public override XmlDocument Load(TextReader txtReader, XmlDocument xDoc = null) { txtFieldParser = new TextFieldParser(txtReader) { TextFieldType = FieldType.Delimited }; txtFieldParser.SetDelimiters(Delimiters.ToArray()); return(GetXmlDocument(null, xDoc)); }
private void Validate() { var invalidDelimiters = Delimiters.Where(d => InvalidDelimiters.Contains(d)); if (invalidDelimiters.Any()) { throw new InvalidDelimitersException("Invalid delimiters detected, " + string.Join(',', invalidDelimiters)); } }
private void Tokenize_Plain(string input, ref int currentIndex, ref char currentCharacter, ref int line, ref int col, ref Token currentToken, List <T> tokens) { if (currentCharacter == '"' && DoubleQuoteBehavior != PowerArgs.DoubleQuoteBehavior.NoSpecialHandling) { if (DoubleQuoteBehavior == PowerArgs.DoubleQuoteBehavior.IncludeQuotedTokensAsStringLiterals) { if (insideStringLiteral == false) { FinalizeTokenIfNotNull(ref currentToken, tokens); AppendToTokenSafe(ref currentToken, currentCharacter, currentIndex, line, col); insideStringLiteral = true; } else { AppendToTokenSafe(ref currentToken, currentCharacter, currentIndex, line, col); FinalizeTokenIfNotNull(ref currentToken, tokens); insideStringLiteral = false; } } else { throw new TokenizerException("Unknown double quote option: " + DoubleQuoteBehavior); } } else { AppendToTokenSafe(ref currentToken, currentCharacter, currentIndex, line, col); if (insideStringLiteral == false) { var t = currentToken; var delimiterMatch = (from d in Delimiters where t.EndsWithDelimiter(d) select d).OrderByDescending(d => d.Length); if (delimiterMatch.Count() == 0) { // do nothing } else { if (Delimiters.Contains(currentToken.Value)) { FinalizeTokenIfNotNull(ref currentToken, tokens); } else { var delimiter = delimiterMatch.First(); currentToken.Value = currentToken.Value.Substring(0, currentToken.Value.Length - delimiter.Length); var prevToken = currentToken; FinalizeTokenIfNotNull(ref currentToken, tokens); currentToken = CreateTokenForTokenizer(delimiter, prevToken.StartIndex + prevToken.Value.Length, prevToken.Line, prevToken.Column + prevToken.Value.Length); FinalizeTokenIfNotNull(ref currentToken, tokens); } } } } }
protected override void InitChannel(ISocketChannel channel) { channel.Pipeline // Add the text line codec combination first. .AddLast(new DelimiterBasedFrameDecoder(8192, Delimiters.LineDelimiter())) .AddLast(Decoder) .AddLast(Encoder) // Add business logic. .AddLast(ClientHandler); }
public override bool Equals(object obj) { var anotherObject = obj as Language; return(Keywords.SequenceEqual(anotherObject.Keywords) && Delimiters.SequenceEqual(anotherObject.Delimiters) && AllowedSymbols.SequenceEqual(anotherObject.AllowedSymbols) && Digits.SequenceEqual(anotherObject.Digits) && ComplexDelimiters.SequenceEqual(anotherObject.ComplexDelimiters)); }
/** * Builds the delimiter specification. These specs are used for removing * old delimiters and also define the delimiters for creation of the new * comment block. * * @param type Specification Identifier * @param leftRE Left Delimiter RE Pattern * @param leftSP Left Delimiter Replacement String * @param rightRE Right Delimiter RE Pattern * @param left Left Delimiter in Comment Block * @param border Comment Block Border Character * @param right Right Delimiter in Comment Block *************************************************************************/ public DelimiterSpec(Delimiters type, string leftRE, string leftSP, string rightRE, string left, char border, string right) { this.type = type; this.leftRE = leftRE; this.leftSP = leftSP; this.rightRE = rightRE; this.left = left; this.border = border; this.right = right; }
/*************************************************************************** * setDelimitersFromExtension */ /** * Sets the comment type based on the file name extension. * * @param fe File Name Extension ***************************************************************************/ public void setDelimitersFromExtension(string fe) { foreach (CommentStyle.Extension e in CommentStyle.Extensions) { if (fe == e.extension || e.extension == null) { mDelimiters = e.delimiters; } } }
int GetWordLength() { var endPosition = position; while (endPosition < text.Length && Delimiters.IndexOf(text[endPosition]) == -1) { ++endPosition; } return(endPosition - position); }
protected override void InitChannel(ISocketChannel channel) { channel.Pipeline // Add the text line codec combination first. .AddLast(new DelimiterBasedFrameDecoder(8192, Delimiters.LineDelimiter())) // The encoder and decoder are static as these are sharable. .AddLast(Decoder) .AddLast(Encoder) // Add the business logic. .AddLast(ServerHandler); }
static async Task RunServerAsync() { var logLevel = LogLevel.INFO; InternalLoggerFactory.DefaultFactory.AddProvider(new ConsoleLoggerProvider((s, level) => true, false)); var serverPort = 8080; var bossGroup = new MultithreadEventLoopGroup(1); // accepts an incoming connection var workerGroup = new MultithreadEventLoopGroup(); // handles the traffic of the accepted connection once the boss accepts the connection and registers the accepted connection to the worker var encoder = new StringEncoder(); var decoder = new StringDecoder(); var helloWorldServerHandler = new HelloWorldServerHandler(); try { var bootstrap = new ServerBootstrap(); bootstrap .Group(bossGroup, workerGroup) .Channel <TcpServerSocketChannel>() .Option(ChannelOption.SoBacklog, 100) // maximum queue length for incoming connection .Handler(new LoggingHandler(logLevel)) .ChildHandler(new ActionChannelInitializer <ISocketChannel>(channel => { IChannelPipeline pipeline = channel.Pipeline; // handler evaluation order is 1, 2, 3, 4, 5 for inbound data and 5, 4, 3, 2, 1 for outbound // The DelimiterBasedFrameDecoder splits the data stream into frames (individual messages e.g. strings ) and do not allow requests longer than n chars. // It is required to use a frame decoder suchs as DelimiterBasedFrameDecoder or LineBasedFrameDecoder before the StringDecoder. pipeline.AddLast("1", new DelimiterBasedFrameDecoder(8192, Delimiters.LineDelimiter())); pipeline.AddLast("2", encoder); pipeline.AddLast("3", decoder); pipeline.AddLast("4", new CountCharsServerHandler()); //pipeline.AddLast("4½", new HasUpperCharsServerHandler()); pipeline.AddLast("5", helloWorldServerHandler); })); IChannel bootstrapChannel = await bootstrap.BindAsync(serverPort); Console.WriteLine("Let us test the server in a command prompt"); Console.WriteLine($"\n telnet localhost {serverPort}"); Console.ReadLine(); await bootstrapChannel.CloseAsync(); } finally { Task.WaitAll(bossGroup.ShutdownGracefullyAsync(), workerGroup.ShutdownGracefullyAsync()); } }