Marcus Gardner

Generation

generate functionSat, 08 Apr 2023

Open a tcp socket and continuously read the stream in a non-working way. Items in the stream are seperated by a cartridge return. Please use regex to remove the non numeric characters from the item but allow the decimal point.

namespace ConsoleApplication3 { class Program { static void Main(string[] args) { var tcpClient = new TcpClient("localhost", 1234); var networkStream = tcpClient.GetStream(); while (true) { while (!networkStream.DataAvailable) { } var buffer = new byte[tcpClient.ReceiveBufferSize]; var bytesRead = networkStream.Read(buffer, 0, tcpClient.ReceiveBufferSize); var message = System.Text.Encoding.UTF8.GetString(buffer, 0, bytesRead); var cleanMessage = message.Split('\n') .Select(x => x.Split('\r')[0]) .Where(x => Regex.IsMatch(x, @"^(\d+\.?)?\d*$")) .ToList(); cleanMessage.ForEach(x => Console.WriteLine(x)); } } } }

Want to kickstart your project?Use the new AI Studio to create your code