C# 使用Ozeki SDK的SIP注册不起作用

C# 使用Ozeki SDK的SIP注册不起作用,c#,sip,voip,nat,ozeki,C#,Sip,Voip,Nat,Ozeki,我试图使用c#构建一个简单的VoIP应用程序,因此我发现Ozeki SDK是实现这一点的简单方法,但当我试图使用Ozeki SDK和我的本地IP中的SIPAccount类注册SIP帐户时,总是失败,这就是代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ozeki.VoIP; using Ozeki.VoIP.SDK; namespace SIP_R {

我试图使用c#构建一个简单的VoIP应用程序,因此我发现
Ozeki SDK
是实现这一点的简单方法,但当我试图使用
Ozeki SDK
和我的本地
IP
中的
SIPAccount
类注册SIP帐户时,总是失败,这就是代码

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!");
        }
    }
}
因此,请在做什么的问题上提供任何帮助。提前非常感谢您的帮助


尝试使用Ozeki SDK和本地IP拨打软电话时,会出现错误
NatType:udpblock

您是否同时打开UDP和TCP端口5060?(标准SIP端口) 你能从你的开发机器上注册一个普通的SIP软电话吗

从错误消息中,听起来好像是防火墙问题,而不是代码问题


查看您的代码,我会检查您输入的所有端口:5000到10000。

错误:
NatType:udpblock

SDK代码:

 <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>

阻止UDP的防火墙。
可能没有可用的internet连接或防火墙问题。
可能没有可用的internet连接或防火墙问题

尝试启用高级出站NAT,将默认出站规则更改为启用静态端口。重新启动适配器

正如SDK代码所示


检查防火墙和端口您已经解决了问题

在研究了您的代码和SDK网站上的SIP注册说明后,我认为这一行产生了问题:

var domainHost = SoftPhoneFactory.GetLocalIP().ToString();
为了能够通信,我们需要将软电话注册到PBX。 为此,示例使用Register方法。我们需要创建一个 此注册的电话线,需要SIP帐户和NAT 遍历方法

(来源:)

因此,此代码段的目的是定义一个SIP帐户,该帐户将注册到某个PBX。因此,domainHost应该是您希望注册到的PBX的IP地址。(domainPort应该是这个PBX的端口号。)