hey!, i wonder if anyone could lend me a hand with the following, below i have a code segment from a class im writing which essentially streams bytes from a network socket and retrives that data and converts it using ASCII into a readable format and at present prints this info out to a text file, this was just for disagnostic purposes, all of this works btw, what i require is to parse the stream presumeabley with a streamreader and look for certain strings within the stream, ive had a complete mind blank and i cannot figure out where i need to start parsing this file, is it within my if statement? and would a streamreader be prefabable? thanks in advance
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Net.Sockets; using System.Threading; using System.IO; namespace RSI_MONITORING { abstract class Comm { protected int port; protected bool type; //true is tcp, false is udp public Comm() { } protected void beginByteLoop(ref TcpClient client, int sleepTime) { NetworkStream ns = client.GetStream(); BinaryReader reader = new BinaryReader(ns, Encoding.ASCII); FileStream dataFile = new FileStream("C:\\results.dat", FileMode.Append); StreamWriter writer = new StreamWriter(dataFile);
System.Collections.ArrayList buffer = new System.Collections.ArrayList(); byte myByte;
while (true) { try { myByte = reader.ReadByte(); } catch (EndOfStreamException e)
{ Console.WriteLine(e); Console.WriteLine("End of stream"); break; }
buffer.Add(myByte);
if (ns.DataAvailable == false) { byte[] convertedBuffer = new byte[buffer.Count]; buffer.CopyTo(convertedBuffer); writer.WriteLine(Encoding.ASCII.GetString(convertedBuffer)); Console.WriteLine(Encoding.ASCII.GetString(convertedBuffer)); } } writer.Close(); } } }
|