-1

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);
}
Conrad
  • 397
  • 1
  • 2
  • 12

1 Answers1

-1

End of AGI command - empty line.

So you shoudl read all upto empty line, discard that line. EVERYTIME.

Or just read source of already compleated libs. There are tens of them.

https://www.voip-info.org/asterisk-agi/

arheops
  • 15,544
  • 1
  • 21
  • 27