Loduwijk
Loduwijk

Reputation: 1977

Programmatically calling my VoIP phone on my network

Here is the environment: There are both PCs and Cisco VoIP phones on our network. There is a phone switch on the network that allows the VoIP phones to call out, but I don't think the switch is relevant for this part of the project.

This is my first time including VoIP into my software, so I'm trying to start by making my PC place a call to my VoIP phone. From the PC, I can ping the phone's IP address and get a response, so I should be able to communicate with it.

With what I have so far, I was hoping that the phone would start ringing. I am using mjsip in Java, and I am getting a call failed message with reason "Request Timeout" and no ring. I do not have any code done yet for what would happen after the phone was answered, but I would like to at least make it ring to start with.

I am hoping that someone with more VoIP experience can either verify or rule out me doing this improperly, or maybe be able to bring more pitfalls to light. For example, can I even expect the phone to respond to a sip call just because it is a VoIP phone? Do I have to go through the phone switch even though it is a VoIP phone on the same network? Is it just a problem with my code?

The code, assuming I have done it properly, is initiating a sip stack, setting up a user profile, and attempted to place a call to a sip address that corresponds to the phone's IP and port 5060 (Google told me sip port is often 5060).

public class SIPTest implements UserAgentListener, SipProviderListener
{
    public static void main(String[] args)
    {
        if(!SipStack.isInit())
            SipStack.init();

        SipProvider sipProvider = new SipProvider("127.0.0.1", 5060);
        UserAgentProfile profile = new UserAgentProfile();
        profile.audio = true;
        profile.hangup_time = 10;
        profile.user = "testuser";
        profile.keepalive_time = 8000;

        final UserAgent userAgent = new UserAgent(sipProvider, profile, new     SIPTest());

        sipProvider.addPromiscuousListener(new SIPTest());
        userAgent.call(new NameAddress(new SipURL("172.16.1.250", 5060)));
        System.out.println("end ...");
    }


    /**
     * begin SipProviderListener
     **/

    public void onReceivedMessage(SipProvider sip_provider,
                    Message message)
    {
        if (message.isInfo())
        {
            System.out.println("Promisque onReceivedMessage ... message " + message.getMethodId().toString() + "\n body = " + message.getBody());
        }
    }

    /**
     * end SipProviderListener
     **/


    /**
     * begin UserAgentListener
     **/

    public void onUaCallAccepted(UserAgent arg0)
    {
        System.out.println("onUaCallAccepted ...");
    }

    public void onUaCallCancelled(UserAgent arg0)
    {
        System.out.println("onUaCallCancelled ...");
    }

    public void onUaCallClosed(UserAgent arg0)
    {
        System.out.println("onUaCallClosed ...");
    }

    public void onUaCallFailed(UserAgent arg0, String reason)
    {
        System.out.println("onUaCallFailed ...");
        System.out.println("\t" + arg0);
        System.out.println("\t" + reason);
    }

    public void onUaCallIncoming(UserAgent arg0,
                            NameAddress arg1, NameAddress arg2)
    {
        System.out.println("onUaCallIncoming ...");
        System.out.println("from " + arg2.toString());
        System.out.println("to " + arg1.toString());

        arg0.accept();
        System.out.println("Call accepted ...");
    }

    public void onUaCallProgress(UserAgent ua)
    {
        System.out.println("onUaCallProgress ...");
    }

    public void onUaCallRinging(UserAgent arg0)
    {
        System.out.println("onUaCallRinging ...");
    }

    public void onUaCallTransferred(UserAgent arg0)
    {
        System.out.println("onUaCallTrasferred ...");
    }

    public void onUaIncomingCall(UserAgent ua, NameAddress callee, NameAddress caller, Vector media_descs)
    {
        System.out.println("onUaIncomingCall ...");
    }

    public void onUaMediaSessionStarted(UserAgent ua, String type, String codec)
    {
        System.out.println("onUaMediaSessionStopped ...");
    }

    public void onUaMediaSessionStopped(UserAgent ua, String type)
    {
        System.out.println("onUaMediaSessionStopped ...");
    }

    public void onUaRegistrationFailed(UserAgent ua, String result)
    {
        System.out.println("onUaRegistrationFailed ...");
    }

    public void onUaRegistrationSucceeded(UserAgent ua, String result)
    {
        System.out.println("onUaRegistrationSucceeded ...");
    }

    /**
     * end UserAgent
     **/
}

If I run that, the following is the output I get.

ExtendedAudioSystem: Supported: PCM_SIGNED PCM_UNSIGNED ALAW ULAW PCM_SIGNED PCM
_UNSIGNED PCM_FLOAT
ExtendedAudioSystem: TargetDataLine: PCM_SIGNED 8000.0 Hz, 16 bit, mono, 2 bytes
/frame, little-endian
ExtendedAudioSystem: Supported: PCM_SIGNED PCM_UNSIGNED ALAW ULAW PCM_SIGNED PCM
_UNSIGNED PCM_FLOAT
ExtendedAudioSystem: SourceDataLine: PCM_SIGNED 8000.0 Hz, 16 bit, mono, 2 bytes
/frame, little-endian
end ...
onUaCallFailed ...
        local.ua.UserAgent@283bbb6
        Request Timeout

Upvotes: 3

Views: 2175

Answers (1)

yohann.martineau
yohann.martineau

Reputation: 1643

In my opinion, the underlying SIP INVITE message (corresponding to userAgent.call) is considered as sent by the sip stack but no answer is received. Thus you get this (408) "Request Timeout" message. 408 request timeout is a SIP response automatically generated by sip stack when no response is received from the remote party (or proxy). Sometimes, for some odd reason, firewall can block outgoing requests and does not notify java that an issue occured while sending packet. Thus, no exception is thrown and application (here, sip stack) can not send the packet again nor notify user of network issue.

Did you check that you could call sip:172.16.1.250 using another sip client from the same host? you can test quickly using sipp (use option -m 1 to start only one call). If you can place a call using another sip client, then there is no firewall issue.

Upvotes: 1

Related Questions