recvEventTimed - SERVER_DISCONNECTED
Dear friends, I've faced an issue in event socket. I would want to know why it behaves such a way. My program is working with the hep of events. So, based on the received event, the process will continue it's work. When I need DTMF, I use recvEventTimed and in the other cases, I use recvEvent. So, In the mid if caller hangsup, I expect for the SERVER_DISCONNECTED event. When the caller hangsup when I'm waiting in recvEvent, I'm getting SERVER_DISCONNECTED. But, when I'm waiting in recvEventTimed, I'mnot receiving SERVER_DISCONNECTED, instead receiving an undefined value. To handle this, I've checked esl connection inside the timeout part and put a recvEvent, then I receive SERVER_DISCONNECTED. My question is, why am I not receiving SERVER_DISCONNECTED when I recv event using recvEventTimed?! This is a sample program I execute, require ESL; use IO::Socket::INET; my $ip = "127.0.0.1"; my $sock = new IO::Socket::INET ( LocalHost => $ip, LocalPort => '9242', Proto => 'tcp', Listen => 1, Reuse => 1 ); die "Could not create socket: $!\n" unless $sock; for(;;) { my $new_sock = $sock->accept(); my $pid = fork(); if ($pid) { close($new_sock); next; } my $host = $new_sock->sockhost(); my $fd = fileno($new_sock); my $con = new ESL::ESLconnection($fd); my $info = $con->getInfo(); my $uuid = $info->getHeader("unique-id"); printf "Connected call %s, from %s\n", $uuid, $info->getHeader("caller-caller-id-number"); my $e = $con->filter("unique-id", $uuid); if ($e) { print $e->serialize(); } else { printf("WTF?\n"); } $con->events("plain", "SERVER_DISCONNECTED DTMF"); $con->execute("answer"); while($con->connected()) { $e = $con->recvEvent(); ############# CASE 1 ## # $e = $con->recvEventTimed(10000); ############# CASE 2 ## unless ($e) { unless ($con->connected()) { ############################### $e = $con->recvEvent(); ## print $e->serialize(); ## Added code to get SERVER_DISCONNECTED. print "SERVER_DISCONNECTED"; ## } ############################### print "DTMF timeout\n"; } if ($e) { my $name = $e->getHeader("event-name"); print "EVENT [$name]\n"; if ($name eq "DTMF") { my $digit = $e->getHeader("dtmf-digit"); my $duration = $e->getHeader("dtmf-duration"); print "DTMF digit $digit ($duration)\n"; } } } print "BYE\n"; close($new_sock); } -- Regards, Nagalenoj H.
Anything wrong with this question?! I didn't find any replies for this.. On Fri, Mar 5, 2010 at 10:37 AM, Nagalenoj H. <nagalenoj@gmail.com> wrote:
Dear friends, I've faced an issue in event socket. I would want to know why it behaves such a way.
My program is working with the hep of events. So, based on the received event, the process will continue it's work. When I need DTMF, I use recvEventTimed and in the other cases, I use recvEvent. So, In the mid if caller hangsup, I expect for the SERVER_DISCONNECTED event. When the caller hangsup when I'm waiting in recvEvent, I'm getting SERVER_DISCONNECTED. But, when I'm waiting in recvEventTimed, I'mnot receiving SERVER_DISCONNECTED, instead receiving an undefined value.
To handle this, I've checked esl connection inside the timeout part and put a recvEvent, then I receive SERVER_DISCONNECTED.
My question is, why am I not receiving SERVER_DISCONNECTED when I recv event using recvEventTimed?!
This is a sample program I execute,
require ESL; use IO::Socket::INET;
my $ip = "127.0.0.1"; my $sock = new IO::Socket::INET ( LocalHost => $ip, LocalPort => '9242', Proto => 'tcp', Listen => 1, Reuse => 1 ); die "Could not create socket: $!\n" unless $sock;
for(;;) { my $new_sock = $sock->accept(); my $pid = fork(); if ($pid) { close($new_sock); next; }
my $host = $new_sock->sockhost(); my $fd = fileno($new_sock);
my $con = new ESL::ESLconnection($fd); my $info = $con->getInfo(); my $uuid = $info->getHeader("unique-id"); printf "Connected call %s, from %s\n", $uuid, $info->getHeader("caller-caller-id-number");
my $e = $con->filter("unique-id", $uuid); if ($e) { print $e->serialize(); } else { printf("WTF?\n"); }
$con->events("plain", "SERVER_DISCONNECTED DTMF"); $con->execute("answer");
while($con->connected()) { $e = $con->recvEvent(); ############# CASE 1 ## # $e = $con->recvEventTimed(10000); ############# CASE 2 ##
unless ($e) { unless ($con->connected()) { ############################### $e = $con->recvEvent(); ## print $e->serialize(); ## Added code to get SERVER_DISCONNECTED. print "SERVER_DISCONNECTED"; ## } ############################### print "DTMF timeout\n"; } if ($e) { my $name = $e->getHeader("event-name"); print "EVENT [$name]\n"; if ($name eq "DTMF") { my $digit = $e->getHeader("dtmf-digit"); my $duration = $e->getHeader("dtmf-duration"); print "DTMF digit $digit ($duration)\n"; } } } print "BYE\n"; close($new_sock); }
-- Regards, Nagalenoj H.
-- Regards, Nagalenoj H.
This is because you're timing out and ending your loop and loosing the event. while($con->connected()) { becomes false and you can't come back around to pickup the event because you would have been disconnected before you had a chance to get the event. recvEventTimed allows you to do other things if you don't receive events in a set amount of time. One example of proper usage on inbound event socket: http://svn.freeswitch.org/svn/freeswitch/trunk/libs/esl/perl/ESL/Dispatch.pm http://svn.freeswitch.org/svn/freeswitch/trunk/libs/esl/perl/dispatch.pl /b On Mar 8, 2010, at 10:33 PM, Nagalenoj H. wrote:
Anything wrong with this question?! I didn't find any replies for this..
participants (2)
-
Brian West
-
Nagalenoj H.