I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2010-03-23 13:54:20.749976-07 by bryanp
loop and addtimer confusion
I'm creating a simple application that registers to a ims core and then subscribes to the presence event package, I want to use this program to display changes in my presence to a console. I've gotten as far as registering, subscribing and receiving a notify but I can't seem to get the loop correct. The problem is that after registration I send out the subscribe over and over again. It seems that the timer isn't working properly. I've posted my code below as well as the debug 100 trace that seems like the problem.
use Net::SIP ':all'; # create new agent use strict; use warnings; Net::SIP::Debug->level(100); my $from = 'sip:+18563029050@ims.cableland.net'; my $to = 'sip:+18563029050@ims.cableland.net'; my $uri = 'sip:+18563029050@ims.cableland.net'; my $callid = '12345'; my $ua = Net::SIP::Simple->new( outgoing_proxy => '10.253.24.93', registrar => 'ims.cableland.net', domain => 'ims.cableland.net', from => 'sip:+18563029050@ims.cableland.net', auth => [ '8563029050@ims.cableland.net','password' ], ); # Register agent print "registering user\n"; $ua->register; print "creating subscribe message\n"; my $subscribe = Request->new( 'SUBSCRIBE', $uri, { to => "<" . $uri .">", from => "<" . $uri .">", cseq => '1 SUBSCRIBE', 'call-id' => '12345', contact => '<sip:+18563029050@10.253.24.174:5060>', 'event' => 'presence', expires => '60000', 'P-Preferred-Identity' => "<" . $uri . ">", 'Accept' => 'application/pidf+xml' }); print "setting up port to receive....\n"; $ua->{dispatcher}->set_receiver(\&receive); $ua->add_timer(0,$ua->{dispatcher}->deliver($subscribe),30000); my $stop_var = 0; $ua->loop(60000,\$stop_var); sub receive { print "packet received\n"; print "------------------\n"; my ($packet, $leg, $from_addr) = @_; #print $packet->as_string; my $callid = $packet->callid() or do { DEBUG( 1, "no callid in packet. DROP" ); return; }; my ( $request,$response ) = $packet->is_response ? ( undef,$packet ) : ( $packet, undef ); if ($response) { my $code = $response->code; if ($code eq '200') { print "Received 200 ok\n"; return; } else { print "received $code\n"; return; } } else { if ($request->method eq 'NOTIFY') { print "received notify\n"; $ua->{dispatcher}->deliver($request->create_response( 200,'OK'), leg => $leg, dst_addr + => $from_addr ); } } } 1269377392.0003 DEBUG:<50> Net::SIP::Dispatcher::Eventloop::loop[135]: trigger timer(disp_expire) 1 +269377391.99868 repeat=1 1269377392.0004 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[140]: timer(disp_expire) gets rep +eated at 1269377392 1269377392.0005 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[152]: timeout = 0.998549938201904 1269377392.0005 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[167]: handles=3 1269377393.0002 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[174]: can_read= 1269377393.0003 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[120]: timeout = 59985.3649139404 1269377393.0003 DEBUG:<50> Net::SIP::Dispatcher::Eventloop::loop[135]: trigger timer(disp_expire) 1 +269377392.99868 repeat=1 1269377393.0004 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[140]: timer(disp_expire) gets rep +eated at 1269377393 1269377393.0005 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[152]: timeout = 0.998558044433594 1269377393.0005 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[167]: handles=3 1269377394.0004 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[174]: can_read= 1269377394.0004 DEBUG:<100> Net::SIP::Dispatcher::Eventloop::loop[120]: timeout = 59984.3647358418
Direct Responses: 12599 | Write a response
Posted on 2010-03-28 12:06:56.177793-07 by noxxi in response to 12592
Re: loop and addtimer confusion
I'm not really sure what you are trying to do.
But a problem is definitly, that you setup a timer with the return code of deliver, which according to the documentation doesn't return anything useful. Therefore it returns anything at all it should not be used as a callback for a timer.
Direct Responses: 12602 | Write a response
Posted on 2010-03-28 19:30:29.209386-07 by bryanp in response to 12599
Re: loop and addtimer confusion
Ok I think I understand. Basically I just want to Subscribe once after registration with the registrar, and then keep the port open so I can receive notifications. The subscribe should happen every 30000 seconds. Would putting the subscribe deliver into a subroutine that always returns true be the correct way to use addTimer? Thanks for the help, this is a really great code effort and will be very useful in the future for me.
Direct Responses: Write a response