kobaz has asked for the wisdom of the Perl Monks concerning the following question:

Using Net::SIP::Simple I'm able to get a basic of basic example going:
my $sock_from = IO::Socket::INET->new( Proto => 'tcp', LocalPort => '5070', LocalAddr => '0.0.0.0', ); my $sock_to = IO::Socket::INET->new( Proto => 'tcp', PeerAddr => 'somesortofsomething', PeerPort => '5060', ); my $leg_from = Net::SIP::Leg->new( sock => $sock_from ); my $leg_to = Net::SIP::Leg->new( sock => $sock_to ); my $ua = Net::SIP::Simple->new( legs => [$leg_from, $leg_to], from => $from, outgoing_proxy => 'something', domain => 'something', ); my $timeout = 5; my $stopvar; $ua->add_timer($timeout , \$stopvar ); my $invite = $ua->invite($to); print Dumper($invite); -------------------

Success! ...kind-of

-> INVITE
<- 401 Unauthorized

I see my whole INVITE conversation in the $invite Dumper.... I've spent some time poking around in the documentation but I can't make heads or tails out of actually how to interact with the sip-server on the other end or what the proper function call would be to get the response (in this case 401)

And in sngrep/tcpdump/etc I'm not seeing an ACK go out

Goal:

What I do want:
- Be able to do a very very basic query of: What was the result of my INVITE... was it a 401? Was it a 200 OK? Was it a 302 Redirect?
- And then... for instance I get a 302 Redirect... read the Contact: header that I've been redirected to.
- Wait a reasonable amount of time (say 5 seconds, and then bail completely if there was no answer)

What I don't want:
- A blocking event-loop
- Don't need to handle RTP


Thanks!

Replies are listed 'Best First'.
Re: Net::SIP Total Newbie question
by Corion (Patriarch) on Mar 10, 2024 at 06:55 UTC

    I think the whole operation of Net::SIP::Simple is asynchronous, so you need to run its event loop in any case (see also its SYNOPSIS):

    ... # Mainloop $ua->loop;

    To react on the call, you want to pass callbacks into ->invite():

    my $call = $ua->invite( $to, cb_final => sub { print "Call finished?\n" }, cb_noanswer => sub { print "Nobody home\n" }, );

    See Net::SIP::Simple::Call for more on the callbacks.

      Thanks.
      Yeah this does look like it. All the normal handling is done in the ua->loop unless you want to write your own.

      On further inspection, the callback I need (ability to read a 302 response), does not exist.

      I went ahead and added my own callback mechanism in NET::SIP::Leg to hit a cb_recieve callback if it's defined

      Now I can read all responses via callback, even the ones that Net::SIP doesn't handle

Re: Net::SIP Total Newbie question
by jwkrahn (Abbot) on Mar 10, 2024 at 03:17 UTC

    I'm not an expert but I believe '0.0.0.0' is not a valid IP address.

    Naked blocks are fun! -- Randal L. Schwartz, Perl hacker
      0.0.0.0 is the universal IPV4 standard for 'bind to all interfaces'

      0.0.0.0

      «The Crux of the Biscuit is the Apostrophe»