我正在尝试使用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:UDPBlocked
发布于 2015-04-21 00:40:44
您是否同时打开了UDP和TCP端口5060?(标准SIP端口)您能从您的开发机器上注册一个普通的SIP软电话吗?
从您的错误消息看,似乎是防火墙问题,而不是代码问题。
看看你的代码,我会检查你输入的所有端口:5000到10000。
发布于 2015-04-28 19:51:41
在研究了您的代码和SDK网站上的SIP注册解释后,我认为这一行会产生问题:
var domainHost = SoftPhoneFactory.GetLocalIP().ToString();为了能够通信,我们需要将我们的软电话注册到PBX。为此,该示例使用Register方法。我们需要为此注册创建一条电话线,这需要SIP帐户和NAT穿越方法。
(来源:How to register to a PBX using SIP Account?)
因此,此代码片段的目的是定义将注册到某个PBX的SIP帐户。相应地,domainHost应该是您希望注册到的用户交换机的IP地址。( domainPort应为此交换机的端口号。)
发布于 2015-04-25 18:19:39
错误: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代码所暗示的那样,
检查防火墙和端口是否已解决问题
https://stackoverflow.com/questions/29442878
复制相似问题