[Asterisk-Users] C Manager Interface Client
Tzafrir Cohen
tzafrir at cohens.org.il
Sat Oct 1 08:19:12 MST 2005
On Fri, Sep 30, 2005 at 11:51:48AM -0500, Tressler, Joshua A wrote:
> List:
>
> This is my first manager client that I've written so please bear with me:
>
> I am trying to write a C manager interface client to interface with our CRM software. I am having an issue while reading the data from the manager interface.
>
> I am writing this in C and I have the following code:
> while(1)
> {
> bzero(buffer,sizeof(buffer));
> readCode = read(socketHandle,buffer,sizeof(buffer));
> if(readCode < 0)
> {
> printf("ERROR READING FROM SOCKET\n");
> exit(0);
> }
> printf("%s",buffer);
> }
This is just the main loop, right? There has to be a login before that.
Could you please post your full code? (that is: a minimal version of it
that you verified to still be problematic).
>
> This prints out everything just as connecting to the telnet session would print it out (I do the logging in elsewhere, that isn't the problem here)
>
> This code will read until * has nothing else for me to read from it
> then print it all out and wait for some more stuff. Since * seems to
> print out on 5038 in "blocks" of text read(...) will never cut off in
> the middle of a block.
Using a C-based program to debug that is not very helpful. telnet
localhost 5038 and see what happens in real-time.
A sniffer could also help.
> However, on one instance, and this is the only one we can reproduce the
> results on, * puts out Event: ****** then stops, Privilege: ********,
> then stops and then prints out the rest. This really screws up my
> parsing as i normally parse using a tokenizer on \r\n\r\n and pass each
> block off to a parsing method. I found this problem using the following code:
> while(1)
> {
> bzero(buffer,sizeof(buffer));
> readCode = read(socketHandle,buffer,sizeof(buffer));
> if(readCode < 0)
> {
> printf("ERROR READING FROM SOCKET\n");
> exit(0);
> }
> printf("%s\n",buffer); ////////This is the main difference \n
> }
> In this case I get output as follows:
> ...
> ...
> .
> .
> Event: Hangup
>
> Privilege: call,all
>
> Channel: SIP/1542200-543f
> Uniqueid: 1128041150.26
> Cause: 0
> Cause-txt: Unknown
> ...
> ...
> .
> .
> In this case "Event: Hangup", "Privilege: call, all", and the rest all get passed off to my parser. Obviously a problem.
>
> Is * spitting this data out to me in three seperate chunks or is my socket not blocking correctly?
>
> Any suggestions as to why this would happen?
>
> TIA,
>
> Joshua
> _______________________________________________
> --Bandwidth and Colocation sponsored by Easynews.com --
>
> Asterisk-Users mailing list
> Asterisk-Users at lists.digium.com
> http://lists.digium.com/mailman/listinfo/asterisk-users
> To UNSUBSCRIBE or update options visit:
> http://lists.digium.com/mailman/listinfo/asterisk-users
--
Tzafrir Cohen | tzafrir at jbr.cohens.org.il | VIM is
http://tzafrir.org.il | | a Mutt's
tzafrir at cohens.org.il | | best
ICQ# 16849755 | | friend
More information about the asterisk-users
mailing list