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. Add each cleaned item to a public queue named rawData.

using System; using System.Collections.Generic; using System.Net.Sockets; using System.Text.RegularExpressions; using System.Net; public class MySocket { public Queue<decimal> rawData = new Queue<decimal>(); public void Connect(string ipAddress, int port) { while(true) { TcpClient tcpclnt = new TcpClient(); tcpclnt.Connect(ipAddress, port); Stream stm = tcpclnt.GetStream(); byte[] ba = new byte[100]; int k = stm.Read(ba, 0, 100); for (int i = 0; i < k; i++) Console.Write(Convert.ToChar(ba[i])); Console.WriteLine(); tcpclnt.Close(); } } }

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