Marcus Gardner

All generations.

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.

function readSocket(host,port,regexString){ var socket = net.connect(port,host); socket.on("data",function(data){ var dataArray = data.toString().split("\r"); var regex = new RegExp(regexString); dataArray.forEach(function(data){ rawData.push(data.replace(regex,"")); }); }); }

Javascript
View
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.

def read_data(self): self.socket.sendall('s\r'.encode()) while True: data = self.socket.recv(1024) for line in data.split('\r'): m = re.match(r'\d*\.\d*',line) if m: self.raw_data.put(float(m.group()))

Python
View
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.

const net = require('net'); const re = /[^\d\.]+/g; const rawData = []; const client = new net.Socket(); client.connect(1025, '127.0.0.1', function() { console.log('Connected'); }); client.on('data', function(data) { const cleanData = data.toString().replace(re, ''); rawData.push(cleanData); }); client.on('close', function() { console.log('Connection closed'); });

Javascript
View
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.

private static Queue<string> rawData = new Queue<string>(); private static Queue<int> cleanData = new Queue<int>(); private static Thread receivingThread; private static void StartReceiving() { receivingThread = new Thread(ReceiveData); receivingThread.IsBackground = true; receivingThread.Start(); } private static void ReceiveData() { TcpClient client = new TcpClient("192.168.1.1", 5000); Stream stream = client.GetStream(); byte[] bytes = new byte[1024]; int length; while (true) { length = stream.Read(bytes, 0, bytes.Length); if (length > 0) { string data = Encoding.ASCII.GetString(bytes, 0, length); var cleanDataLines = Regex.Matches(data, @"\d*\.?\d+").Cast<Match>().Select(m

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.

import re import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((TCP_IP, TCP_PORT)) s.send("READ") while True: data = s.recv(BUFFER_SIZE) data = data.replace("\n", "") data = data.replace("\r", "") data = re.sub("[^0-9.]", "", data) rawData.put(data)

Javascript
View
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);

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(); } } }

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)); } } } }

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 queue named rawData.

using System; using System.Collections.Generic; using System.IO; using System.Net; using System.Net.Sockets; using System.Text.RegularExpressions; using System.Threading; namespace MultiThreading.Tasks { public class TankData { public int TankId { get; set; } public string TankName { get; set; } public double Gallons { get; set; } } public class TankDataReader { private const string IP = "192.168.0.3"; private const int PORT = 8085; private const int ID = 1; private const string NAME = "Tank1"; private const double CONVERSIONFACTOR = 6.4; //The number of gallons (U.S.) per unit. private const int READLOOPDELAY = 1000; public void ReadTankData(Queue<TankData> rawData) { TcpClient socket = new TcpClient(); socket.Connect(IP,

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.

function parseData(data) { // regex /[^\d.-]/g data = data.replace(/[^\d.-]/g, ''); rawData.push(data); } var net = require('net'); var client = new net.Socket(); client.connect(3000, '127.0.0.1', function() { console.log('Connected'); client.write('Hello, server! Love, Client.'); }); client.on('data', function(data) { console.log('Received: ' + data); parseData(data); client.destroy(); // kill client after server's response }); client.on('close', function() { console.log('Connection closed'); });

Javascript
View

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