StreamReader alternative that treats null char (\0) as line ending
I have a client program that receives streaming XML messages from a remote server. These streams provide real-time updates to various sporting events, and it runs forever; even when there are no updates to transmit, it still sends a keep-alive message every 45 seconds.
The service in question has two feeds with different details. The first feed terminates each XML message with a carriage-return/line-feed pair (0d, 0a), which means it's very easy to consume with StreamReader. EG:
using (TcpClient Client = new TcpClient(this.Host, this.Port))
{
using (NetworkStream stream = Client.GetStream())
{
StreamReader reader = new StreamReader(stream);
while (!reader.EndOfStream)
{
String message = reader.ReadLine();
ProcessMessage(message);
}
}
}
The second feed, however, does not terminate with CR/LF but only with null characters ( ), which StreamReader.ReadLine() does not treat as the end of a line, so it blocks forever waiting for something that will never come.
I can't write this to a file first, and I can't make the company providing the feeds change anything because it's already being consumed by others.
Is there an alternative to StreamReader that will consider a null char to be an end-of-line terminator?
CustomStreamReader class - terminates on either '