plasmatwin
Programmer
I'm writing an IRC client library in c# using the Aynchronous Socket model in .NET. I am currently at a problem where, when recieving data from the socket, the program simply fills its buffer (a byte[256]) with data from the socket and hands it to me. The problem is that this array could contain a single line (often does) or it could contain half a line (since the line is longer than 256 chars) or it could contain 2 lines (if two lines arrived in the socket in the time it took me to perform the read after recieving the last lot) it could also contain one and a half lines. Therefor I need some code that inspects the array and sepperates it into it's sepperate lines. I have a string builder in my state object for the purpose of storing peices of a line that is split across two reads, but I have no idea on how to do the inspection of the array... here is my state object:
ideas?
Code:
class StateObject
{
// Size of receive buffer.
public const int BufferSize = 512;
// Receive buffer.
public byte[] buffer = new byte[BufferSize];
// Received data string.
public StringBuilder sb = new StringBuilder();
}
ideas?