SIP registration using Ozeki SDK not working

4.3k views Asked by At

i'm trying to build a simple VoIP application using c# so i found that the Ozeki SDK is the simple way to do that but when i'm trying to registration SIP account using the SIPAccount class from the Ozeki SDK and my local IP it fail always and this is the code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ozeki.VoIP;
using Ozeki.VoIP.SDK;

namespace SIP_R
{
    class Program
    {
        private static ISoftPhone softphone;   // softphone object
        private static IPhoneLine phoneLine;   // phoneline object

        private static void Main(string[] args)
        {
            // Create a softphone object with RTP port range 5000-10000
            softphone = SoftPhoneFactory.CreateSoftPhone(5000, 10000);

            // SIP account registration data, (supplied by your VoIP service provider)
            var registrationRequired = true;
            var userName = "1000";
            var displayName = "1000";
            var authenticationId = "1000";
            var registerPassword = "1000";
            var domainHost = SoftPhoneFactory.GetLocalIP().ToString();
            var domainPort = 9000;

            var account = new SIPAccount(registrationRequired, displayName, userName, authenticationId, registerPassword, domainHost, domainPort);

            // Send SIP regitration request
            RegisterAccount(account);

            // Prevents the termination of the application
            Console.ReadLine();
        }

        static void RegisterAccount(SIPAccount account)
        {
            try
            {
                phoneLine = softphone.CreatePhoneLine(account);
                phoneLine.RegistrationStateChanged += sipAccount_RegStateChanged;
                softphone.RegisterPhoneLine(phoneLine);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error during SIP registration: " + ex);
            }
        }

        static void sipAccount_RegStateChanged(object sender, RegistrationStateChangedArgs e)
        {
            if (e.State == RegState.Error || e.State == RegState.NotRegistered)
                Console.WriteLine("Registration failed!");

            if (e.State == RegState.RegistrationSucceeded)
                Console.WriteLine("Registration succeeded - Online!");
        }
    }
}

so please any help on what to do many thanks in advance for any help..

when trying to make softphone calls using Ozeki SDK and local IP it give an error NatType:UDPBlocked

3

There are 3 answers

0
Shahzad Qureshi On

Do you have both UDP and TCP port 5060 open? (The standard SIP Port) Can you register a normal SIP softphone from your development machine?

From your error message it sounds like you have a firewall issue, not a code issue.

And looking at your code, I would check all the ports you've entered: 5,000 through 10,000.

0
gregibbot On

After studying your code and the SIP registration explanation at the SDK's website, I think this line generates the problem:

var domainHost = SoftPhoneFactory.GetLocalIP().ToString();

To be able to communicate, we need to register our softphone to a PBX. To do this, the example uses the Register method. We need to create a phone line for this registration, which needs a SIP account and a NAT Traversal method.

(Source: How to register to a PBX using SIP Account?)

So the aim of this code snippet is to define a SIP account that will be registered to a certain PBX. Accordingly, the domainHost should be the IP address of the PBX that you wish to register to. (And the domainPort should be the port number of this PBX.)

0
Tharif On

Error : NatType:UDPBlocked

SDK code :

 <member name="F:Ozeki.Network.Nat.NatType.UdpBlocked">
      <summary>
            Firewall that blocks UDP.
            </summary>
      <remarks>
            Probably no internet connection available or firewall issue.
            </remarks>
    </member>

Probably no internet connection available or firewall issue.

Try Enabling advanced outbound NAT, change the default outbound rule to enable static-port. Reboot adapter.

As the SDK code suggests,

Check Firewall and ports you have the issue tackled