Messtone LLC Manages(TCP):

Azure Microsoft.com TCP Server with NetworkStream, Messtone would write in .NET before Pipelines as follows`async Task ProcessLinesAsync(NetworkStream stream){var buffer=new byte[1024];await stream.ReadAsync(buffer,0,buffer.length);//Process a single line from the buffer ProcessLine(buffer);}Parse all of the lines returned in the buffer async Task ProcessLinesAsync(NetworkStream stream){var buffer=new byte[1024];var bytesBuffered=0;var bytesConsumed=0;while(true){var byteRead=await stream.ReadAsync(buffer,bytesBuffered,buffer.Length – bytesBuffered);if(bytesRead==0){//EOF break;}//Keep track of this amount of buffered bytes bytesBuffered +=bytesRead;var linePosition = -1;do{//look for a EOL in the buffered data linePositiom=Array.IndexOf(buffer,(byte)’\n’,bytesConsumed,bytesBuffered – bytesConsumed);if(linePosition>=0){//Calculate the length of the line based on the offset bar lineLength=linePosition – bytesConsumed;//Process the line ProcessLine(buffer,bytesConsumed,lineLength);//Move the bytesConsumed to skip past the line we consumed(including \n)bytesConsumed +=lineLength + 1;}}while(linePosition >=0);}} async Task ProcessLineAsync(NetworkStream stream){byte[ ]buffer=ArrayPool<byte>.Shared.Rent(1024);var bytesBuffered=0;var bytesConsumed=0;while(true){//Calculate the amount of bytes remaining in the buffer var bytesRemaining=buffer.Length – bytesBuffered;if(bytesRemaining==0){//Double the buffer size and copy the previously buffered data into the new buffer var newBuffer=ArrayPool<byte>.Shared.Rent(buffer.Length * 2);Buffer.BlockCopy(buffer,0,newBuffer,0,buffer.Length);Return the old buffer to the poolvArrayPool<byte>.Shared.Return(buffer);buffer=newBuffer;bytesRemaining=buffer.Length – bytesBuffered;}var bytesRead=await stream.ReadAsync(buffer,bytesBuffered,bytesRemaining);if(bytesRead==0){//EOF break;}//Keep track of the amount of buffered bytes bytesBuffered +=bytesRead;do{//Look for a EOL in the buffered data linePosition=Array.IndexOf(buffer,(bytes) ‘\n’,bytesConsumed,bytesBuffered – bytesConsumed);if(linePosition>=0){//Calculate length of the line based on the offset bar lineLength=linePosition – bytesConsumed;//Process the line ProcessLine(buffer,bytesConsumed,lineLength);//Move the bytesConsumed to skip past the line we consumed(including \n) bytesConsumed +=lineLength + 1;}}while(linePosition >=0);}}

Leave a comment