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. Use regex to remove the non numeric characters but allowing the decimal point from the item and add each cleaned item to a public queue named rawData.

using System; using System.Net.Sockets; using System.Text.RegularExpressions; using System.Threading; namespace TcpReader { class Program { public static Queue<float> rawData = new Queue<float>(); static void Main(string[] args) { TcpClient client = new TcpClient("127.0.0.1", 13000); NetworkStream ns = client.GetStream(); StreamReader sr = new StreamReader(ns); try { while (true) { string line = sr.ReadLine(); if (line == null) { continue; } string pattern = @"[^0-9.]+"; string replacement = ""; Regex rgx = new Regex(pattern); string result = rgx.Replace(line, replacement); float number; if (float.TryParse(result, out number)) { rawData.Enqueue(number);

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