2015-04-04 55 views
9

我试图用c#构建一个简单的VoIP应用程序,所以我发现Ozeki SDK是这样做的简单方法,但是当我尝试使用SIPAccount类的注册SIP帐户时在Ozeki SDK和我的本地IP它总是失败,这是代码使用Ozeki SDK不工作的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!"); 
     } 
    } 
} 

所以务必提前任何帮助,该怎么做许多感谢任何帮助..

试图让网络电话通话时使用大关SDK和本地IP给它一个错误NatType:UDPBlocked

回答

1

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

从您的错误消息,它听起来像你有防火墙问题,而不是代码问题。

并看着你的代码,我会检查你输入的所有端口:5,000到10,000。

0

错误:NatType:UDPBlocked

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> 

恐怕没有互联网连接可用或防火墙问题。

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

随着SDK代码表明,

检查防火墙和端口你的问题解决

0

学习你的代码和SDK的网站SIP注册解释之后,我觉得这条线产生的问题:

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

为了能够沟通,我们需要将我们的软电话注册到PBX。 为此,该示例使用Register方法。我们需要为此注册创建一个 电话线,该电话线需要一个SIP帐户和一个NAT穿越方法。

(来源:How to register to a PBX using SIP Account?

所以此代码段的目的是定义将被注册到一定PBX一个SIP账户。因此,domainHost应该是您希望注册到的PBX的IP地址。 (并且domainPort应该是该集团电话的端口号。)