I am communicating with Asterisk via AGI, so im using:
Console.WriteLine(command);
and then:
string res = Console.ReadLine();
to read the response.
This all works fine almost all of the time.
When the response has multiple lines, only first line is read. eg:
<Message/ast_msg_queue>AGI Tx >> 200 result=1 (Line 1
Line 2)
How do I read the response even if it's n lines long?
Tests so far:
StringBuilder sb = new StringBuilder();
int x;
while (true) {
x = Console.Read();
if (x == -1) break; // This never occurs
sb.Append(Convert.ToChar(x));
}
The above code creates an infinite loop, and so does this:
StringBuilder sb = new StringBuilder();
string line;
while ((line = Console.ReadLine()) != null) {
sb.AppendLine(line);
}