# Variable AMI message length

**URL:** <https://community.asterisk.org/t/variable-ami-message-length/42317>\
**Category:** Asterisk General\
**Created:** [April 2, 2013, 1:24pm UTC](https://community.asterisk.org/t/variable-ami-message-length/42317 "2013-04-02T13:24:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![burteaga](https://avatars.discourse-cdn.com/v4/letter/b/9fc29f/32.png) [@burteaga](https://community.asterisk.org/u/burteaga)\
**Post date:** [April 2, 2013, 1:24pm UTC](https://community.asterisk.org/t/variable-ami-message-length/42317/1 "2013-04-02T13:24:17Z")

</div>

Hi all,

I’m having a little problem with my AMI parser.

First of all, I’m using Asterisk 1.8.12.1 and I’ve created an AMI parser which will make it possible to control asterisk with another tool. However, I’m getting some trouble with the message length used by asterisk. In my code, I start a thread which will be listening on a telnet tcp socket and every time I get a message containing the string “Event: hangup” I do some actions. The problem is that when the message I get contains more than one “Event:hangup” the information about the channel being hangup is lost, so I’d like to know: Is there any way to set a maximum length for the AMI messages sent by Asterisk?

Any help will be appreciated,

Ben.

---

<div class="post-metadata">

**Author:** ![david55](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@david55](https://community.asterisk.org/u/david55)\
**Post date:** [April 2, 2013, 1:31pm UTC](https://community.asterisk.org/t/variable-ami-message-length/42317/2 "2013-04-02T13:31:41Z")

</div>

It is the OS TCP layer that is consolidating the messages. Google “Nagle algorithm” for details.

The correct way to handle this is accumulate everything between paired newlines, even if it is split across two frames.

---

<div class="post-metadata">

**Author:** ![burteaga](https://avatars.discourse-cdn.com/v4/letter/b/9fc29f/32.png) [@burteaga](https://community.asterisk.org/u/burteaga)\
**Post date:** [April 2, 2013, 3:10pm UTC](https://community.asterisk.org/t/variable-ami-message-length/42317/3 "2013-04-02T15:10:15Z")

</div>

hey David55 thank you!

When you say Paired newlines you mean “\n\n” or “\r\n” ?

Sorry but it has been an issue since I started with all this stuff…

Thanks in advance!

Ben.

---

<div class="post-metadata">

**Author:** ![burteaga](https://avatars.discourse-cdn.com/v4/letter/b/9fc29f/32.png) [@burteaga](https://community.asterisk.org/u/burteaga)\
**Post date:** [April 3, 2013, 9:21am UTC](https://community.asterisk.org/t/variable-ami-message-length/42317/4 "2013-04-03T09:21:49Z")

</div>

Ok, you meant “\r\n\r\n” actually…

Thanks david!
