2015-04-04 20 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應該是該集團電話的端口號。)