Java MJSIP:向服务器注册android客户端:ONUAregistration失败;Wireshark 400/错误请求

Java MJSIP:向服务器注册android客户端:ONUAregistration失败;Wireshark 400/错误请求,java,android,sip,freeswitch,mjsip,Java,Android,Sip,Freeswitch,Mjsip,“喂 我尝试用MJSIP为android开发一款软电话。我有一个简单的测试设置: 1台带sip电话(1000号)的PC(Win7) 1个VM(Win7),安装了sip电话(号码1001)和Freeswitch sip电话#1000可以拨打#1001和留言。 在虚拟机上,我运行eclipse,尝试用Freeswitch注册android虹吸(编号1002)。但我总是因为注册失败而受伤 public class MainActivity extends Activity { private s

“喂

我尝试用MJSIP为android开发一款软电话。我有一个简单的测试设置:

  • 1台带sip电话(1000号)的PC(Win7)
  • 1个VM(Win7),安装了sip电话(号码1001)和Freeswitch
sip电话#1000可以拨打#1001和留言。 在虚拟机上,我运行eclipse,尝试用Freeswitch注册android虹吸(编号1002)。但我总是因为注册失败而受伤

public class MainActivity extends Activity {

private static final String TAG = "Mjsip-Test-App|| ";
private IpAddress ip;
private int port = 5060;
int audioport = 3000;
private String password = "1234";
private String username = "1002";
private String realm = "172.22.0.34";
String fromUrl = "<sip:" + username + "@" + realm + ":" + port+">"; // FROM
String toUrl = "<sip:" + "1000@" + realm + ":" + port+">"; // TO

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Log.v(TAG, "Start");
    if(!SipStack.isInit()){
    SipStack.init();
    Log.v(TAG, "Stack.init");
    }
    ip = IpAddress.getLocalHostAddress();
    SipProvider sipProvider = new SipProvider(ip.toString(), port);
    Log.v(TAG, "IP: " + ip.toString() + " port: " + port);
    Log.v(TAG, "new sipProvider created");
    UserAgentProfile profile = new UserAgentProfile();
    profile.audio = true;// using audio
    profile.audio_port = audioport;
    profile.passwd = password;
    profile.username = username;
    profile.realm = realm;
    Log.v(TAG, "new profile");

    RegisterAgent reg = new RegisterAgent(sipProvider, toUrl, fromUrl,
            username, realm, password, new RegisterAgentListener() {

                @Override
                public void onUaRegistrationSuccess(RegisterAgent ra,
                        NameAddress target, NameAddress contact,
                        String result) {
                    Log.v(TAG, "Listener: onUaRegistrationSuccess");

                }

                @Override
                public void onUaRegistrationFailure(RegisterAgent ra,
                        NameAddress target, NameAddress contact,
                        String result) {
                    Log.v(TAG, "Listener: onUaRegistrationFailure");
                }
            });

    reg.register();
    Log.v(TAG, "reg.register()");
有人能告诉我如何注册android模拟器吗?为什么我的注册失败了

thx

edit1:我改变了一些小事情,再次测试并查看wireshark

来自wireshark: 400请求:

REGISTER sip:172.22.0.33:5060 SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:5060;rport;branch=z9hG4bK11085
Max-Forwards: 70
To: <sip:1000@172.22.0.33:5060>
From: <sip:1000@172.22.0.33:5060>;tag=z9hG4bK15659795
Call-ID: 522184753761@127.0.0.1
CSeq: 1 REGISTER
Contact: <sip:1002@172.22.0.33:5060>
Expires: 3600
User-Agent: mjsip stack 1.6
Content-Length: 0
在pc的wlan中使用真实设备进行edit7测试:

06-20 09:48:23.576: V/Mjsip-Test-App||(9988): Start 
06-20 09:48:23.584: V/Mjsip-Test-App||(9988): IP: 192.168.173.176
06-20 09:48:23.584: V/Mjsip-Test-App||(9988): Stack.init
06-20 09:48:23.599: V/Mjsip-Test-App||(9988): IP: 192.168.173.176 port: 5554
06-20 09:48:23.599: V/Mjsip-Test-App||(9988): new sipProvider created
06-20 09:48:23.599: V/Mjsip-Test-App||(9988): new profile
06-20 09:48:23.599: V/Mjsip-Test-App||(9988): From: <sip:1002@172.22.0.34>
06-20 09:48:23.599: V/Mjsip-Test-App||(9988): To: <sip:1002@172.22.0.34>
06-20 09:48:23.677: V/Mjsip-Test-App||(9988): reg.register()
06-20 09:50:31.678: V/Mjsip-Test-App||(9988): Listener: onUaRegistrationFailure
06-20 09:50:31.678: V/Mjsip-Test-App||(9988): RegisterAgent: org.hsc.sip.ua.core.core.RegisterAgent@405373f0
06-20 09:50:31.678: V/Mjsip-Test-App||(9988): target: <sip:1002@172.22.0.34>
06-20 09:50:31.678: V/Mjsip-Test-App||(9988): contact: <sip:1002@172.22.0.34>
06-20 09:50:31.678: V/Mjsip-Test-App||(9988): Result: Timeout
06-20 09:50:31.755: I/System.out(9988): UA: NOT FOUND/TIMEOUT
06-20 09:48:23.576:V/Mjsip测试应用程序| |(9988):开始
06-20 09:48:23.584:V/Mjsip测试应用程序| | |(9988):IP:192.168.173.176
06-20 09:48:23.584:V/Mjsip测试应用程序| |(9988):Stack.init
06-20 09:48:23.599:V/Mjsip测试应用程序| |(9988):IP:192.168.173.176端口:5554
06-20 09:48:23.599:V/Mjsip测试应用程序| | |(9988):创建新的sipProvider
06-20 09:48:23.599:V/Mjsip测试应用程序| | |(9988):新配置文件
06-20 09:48:23.599:V/Mjsip测试应用程序| | |(9988):发件人:
06-20 09:48:23.599:V/Mjsip测试应用程序| | |(9988):至:
06-20 09:48:23.677:V/Mjsip测试应用程序| | |(9988):注册寄存器()
06-20 09:50:31.678:V/Mjsip测试应用程序| | |(9988):侦听器:ONA注册失败
06-20 09:50:31.678:V/Mjsip测试应用程序| |(9988):RegisterAgent:org.hsc.sip.ua.core.core。RegisterAgent@405373f0
06-20 09:50:31.678:V/Mjsip测试应用程序| | |(9988):目标:
06-20 09:50:31.678:V/Mjsip测试应用程序| | |(9988):联系方式:
06-20 09:50:31.678:V/Mjsip测试应用程序| |(9988):结果:超时
06-20 09:50:31.755:输入/系统输出(9988):UA:未找到/超时

我不确定您是否成功地将请求从模拟器发送到服务器(虚拟机中的Freeswitch),您是否确保可以在模拟器中使用wifi?即使SIP帧在Wireshark中,也不意味着它已到达目的地,它可能只意味着它已被发送。“Via”字段必须包含“真实/物理”IP地址(在您的情况下),而不是“逻辑”(环回)IP地址,换句话说,127.0.0.1:5060必须是发送设备的IPv4地址。您将使用IpAddress.getLocalHostAddress()获取Via字段(与SipProvider构造函数中的参数地址相同),该字段返回127.0.0.1,这只能表示您的仿真器未“连接”到任何网络。我建议您更改默认端口,尝试“手动/静态”设置via地址(在SipProvider构造函数中),并验证您的虚拟网络设置。正如您在问题中提供的注册消息一样,您似乎正在将注册消息[返回]发送到PC[仿真器]而不是VM

注册消息没有400代码,400 SIP代码代表“错误请求”

您必须提供注册失败原因(代码+原因),该原因可以是以下原因之一(如果不是注册超时):
-“401 Unauthorized”:您必须重新发送带有身份验证(或Www身份验证)标头的注册消息,该标头包含由用户(注册)凭据生成的响应以及服务器对发送的第一条注册消息的回复提供的“nonce”(密钥)。
-“403禁止”:服务器拒绝“处理”您的请求。
-“404未找到”:在服务器的“记录”中找不到请求(注册)的用户
-“407未经授权”(不适用于您的情况)用于代理身份验证。
-等等()

在onUaRegistrationFailure()方法中,在Logcat中打印“result”字符串。
问题也可能是由于MjSip的许多API没有完全实现。

您引用的第二条SIP消息证明您正在将注册消息发送到仿真器本身,而仿真器正在向您发回405错误,因为它充当UAC而不是UAS,因此不允许接收注册消息。(两条消息包含相同的用户代理签名:mjsip-1.6 Freeswitch服务器应具有其他UA签名)。您的服务器(领域)的IP地址是什么?检查您是否已配置一个工作的虚拟网络,然后在您的虚拟机中进行IP配置。w您在Wireshark中看不到任何内容,因为您没有在虚拟机中使用它!在VM中打开Wireshark并尝试注册,您将找到注册请求和服务器的回复。403禁止表示您已成功与服务器通信,但您必须更改服务器的配置,使其能够接受注册消息,或者必须更改注册消息本身中的某些内容,使其能够被服务器接受。您确定SIP[from]源端口和SIP[to]目的港是否相同?在您的配置中,您仅设置源端口。目标端口(服务器的SIP端口)必须与服务器的配置相同,可能是默认端口5060。此外,我不明白为什么会有邀请消息跟踪?请尝试将端口从“收件人”和“发件人”地址ommit:String fromUrl=“”;//来自字符串toUrl=“”;//我对Freeswitch不太熟悉,我只是用了一会儿星号。我认为您应该自己重新实现RegisterAgent,因为大多数MjSIP API都是不完整的,有时甚至是无用的!这里是指向Sipdroid的RegisterAgent源代码的链接。在本例中,我认为服务器的身份验证摘要操作没有正确完成!另一个小细节:我以为你想注册用户1002,那么为什么在Freeswitch日志中用户是1001?!
REGISTER sip:172.22.0.33:54321 SIP/2.0
Via: SIP/2.0/UDP 10.0.2.15:54321;rport;branch=z9hG4bK49856
Max-Forwards: 70
To: <sip:1000@172.22.0.33:54321>
From: <sip:1000@172.22.0.33:54321>;tag=z9hG4bK23560417
Call-ID: 241065424059@10.0.2.15
CSeq: 1 REGISTER
Contact: <sip:1002@172.22.0.33:54321>
Expires: 3600
User-Agent: mjsip stack 1.6
Content-Length: 0
private String ip = "10.0.2.15";
private int port = 5060;
int audioport = 3000;
private String password = "1234";
private String username = "1001";
private String realm = "172.22.0.34";
String fromUrl = "<sip:" + username + "@" + realm + ":" + port + ">"; // FROM
String toUrl = "<sip:" + "1001@" + realm + ":" + port + ">"; // TO

Result 403 Forbidden
---> Wireshark is empty
private String ip = "10.0.2.15";
private int port = 5554;
int audioport = 3000;
private String password = "1234";
private String username = "1001";
private String realm = "172.22.0.34";
String fromUrl = "<sip:" + username + "@" + realm + ":" + port + ">"; // FROM
String toUrl = "<sip:" + "1001@" + realm + ":" + port + ">"; // TO

06-18 08:42:52.617: V/Mjsip-Test-App||(2108): Result: Timeout
  06-18 08:42:52.927: I/System.out(2108): UA: NOT FOUND/TIMEOUT

  ---> Wireshark is empty
private String ip = "10.0.2.15";
private int port = 5554;
int audioport = 3000;
private String password = "1234";
private String username = "1001";
private String realm = "172.22.0.31";
String fromUrl = "<sip:" + username + "@" + realm + ":" + port + ">"; // FROM
String toUrl = "<sip:" + "1001@" + realm + ":" + port + ">"; // TO

Result:
06-18 08:47:24.529: V/Mjsip-Test-App||(2191): Result: Timeout
06-18 08:47:24.828: I/System.out(2191): UA: NOT FOUND/TIMEOUT

Wireshark:
REGISTER sip:172.22.0.31:5554 SIP/2.0
Via: SIP/2.0/UDP 10.0.2.15:5554;rport;branch=z9hG4bK81091
Max-Forwards: 70
To: <sip:1001@172.22.0.31:5554>
From: <sip:1001@172.22.0.31:5554>;tag=z9hG4bK13966145
Call-ID: 270499704138@10.0.2.15
CSeq: 1 REGISTER
Contact: <sip:1001@172.22.0.31:5554>
Expires: 3600
User-Agent: mjsip stack 1.6
Content-Length: 0

INVITE sip:1001@172.22.0.31:5554 SIP/2.0
Via: SIP/2.0/UDP 10.0.2.15:5554;rport;branch=z9hG4bK35740
Max-Forwards: 70
To: <sip:1001@172.22.0.31:5554>
From: <sip:1001@10.0.2.15:5554>;tag=z9hG4bK16532567
Call-ID: 020447961933@10.0.2.15
CSeq: 1 INVITE
Contact: <sip:1001@10.0.2.15:5554>
Expires: 3600
User-Agent: mjsip stack 1.6
Content-Length: 145
Content-Type: application/sdp

v=0
o=sip:1001@10.0.2.15:5554 0 0 IN IP4 10.0.2.15
s=Session SIP/SDP
c=IN IP4 10.0.2.15
t=0 0
m=audio 3000 RTP/AVP 0
a=rtpmap:0 PCMU/8000
REGISTER sip:172.22.0.31:5554 SIP/2.0
Via: SIP/2.0/UDP 10.0.2.15:5554;rport;branch=z9hG4bK81091
Max-Forwards: 70
To: <sip:1001@172.22.0.31:5554>
From: <sip:1001@172.22.0.31:5554>;tag=z9hG4bK13966145
Call-ID: 270499704138@10.0.2.15
CSeq: 1 REGISTER
Contact: <sip:1001@172.22.0.31:5554>
Expires: 3600
User-Agent: mjsip stack 1.6
Content-Length: 0
REGISTER sip:172.22.0.34 SIP/2.0
Via: SIP/2.0/UDP 172.22.0.33:38170;branch=z9hG4bK-d8754z-f3f38111bfc1d85a-1---d8754z-;rport
Max-Forwards: 70
Contact: <sip:1000@172.22.0.33:38170;rinstance=d3164432408a0132>;expires=0
To: "SipTestAcc1000"<sip:1000@172.22.0.34>
From: "SipTestAcc1000"<sip:1000@172.22.0.34>;tag=5f26a73a
Call-ID: YjAwMTQ2MmY4ZTU3MThhZjI2NTBlN2MwYTEzMWFjYTI
CSeq: 3 REGISTER
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO
User-Agent: X-Lite release 4.5.2 stamp 70142
Authorization: Digest    username="1000",realm="172.22.0.34",nonce="495a96a8-00d9-4d01-9976-0c1abd541874",uri="sip:172.22.0.34",response="b99aeb2f5c8f14282f91f6130d14b584",cnonce="efe1a8fc4b143d1f711fac8efe63e4e3",nc=00000002,qop=auth,algorithm=MD5
Content-Length: 0


NOTIFY sip:1000@172.22.0.33:38170 SIP/2.0
Via: SIP/2.0/UDP 172.22.0.34;rport;branch=z9hG4bKFaS6H1D4yU1cQ
Max-Forwards: 70
From: "SipTestAcc1000" <sip:1000@172.22.0.34>;tag=axGJLLkPBvdL
To: "SipTestAcc1000" <sip:1000@172.22.0.34>;tag=0079587c
Call-ID: MDE1OWU0ODEzMDY0NDU3N2M0NmQ0OWI1NTVkOGM5ZjE
CSeq: 45446966 NOTIFY
Contact: <sip:1000@172.22.0.34:5060>
Expires: 0
User-Agent: FreeSWITCH-mod_sofia/1.5.2b+git~20130607T065407Z~e7fa70416d
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY,   PUBLISH, SUBSCRIBE
Supported: timer, precondition, path, replaces
Allow-Events: talk, hold, conference, presence, dialog, line-seize, call-info, sla, include-session-description, presence.winfo, message-summary, refer
Subscription-State: terminated;reason=noresource
Content-Length: 0



SIP/2.0 200 OK
Via: SIP/2.0/UDP 172.22.0.34;rport=5060;branch=z9hG4bKFaS6H1D4yU1cQ
Contact: <sip:1000@172.22.0.33:38170>
To: "SipTestAcc1000"<sip:1000@172.22.0.34>;tag=0079587c
From: "SipTestAcc1000"<sip:1000@172.22.0.34>;tag=axGJLLkPBvdL
Call-ID: MDE1OWU0ODEzMDY0NDU3N2M0NmQ0OWI1NTVkOGM5ZjE
CSeq: 45446966 NOTIFY
User-Agent: X-Lite release 4.5.2 stamp 70142
Content-Length: 0


SIP/2.0 200 OK
Via: SIP/2.0/UDP 172.22.0.33:38170;branch=z9hG4bK-d8754z-f3f38111bfc1d85a-1---d8754z-;rport=38170
From: "SipTestAcc1000" <sip:1000@172.22.0.34>;tag=5f26a73a
To: "SipTestAcc1000" <sip:1000@172.22.0.34>;tag=FQZ535ytt8m1S
Call-ID: YjAwMTQ2MmY4ZTU3MThhZjI2NTBlN2MwYTEzMWFjYTI
CSeq: 3 REGISTER
Date: Tue, 18 Jun 2013 14:34:21 GMT
User-Agent: FreeSWITCH-mod_sofia/1.5.2b+git~20130607T065407Z~e7fa70416d
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: timer, precondition, path, replaces
Content-Length: 0



SUBSCRIBE sip:1000@172.22.0.34:5060;transport=udp SIP/2.0
Via: SIP/2.0/UDP 172.22.0.33:38170;branch=z9hG4bK-d8754z-64e0fd2ee573d443-1---d8754z-;rport
Max-Forwards: 70
Contact: <sip:1000@172.22.0.33:38170>
To: "SipTestAcc1000"<sip:1000@172.22.0.34>;tag=axGJLLkPBvdL
From: "SipTestAcc1000"<sip:1000@172.22.0.34>;tag=0079587c
Call-ID: MDE1OWU0ODEzMDY0NDU3N2M0NmQ0OWI1NTVkOGM5ZjE
CSeq: 3 SUBSCRIBE
Expires: 0
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO
Supported: eventlist
User-Agent: X-Lite release 4.5.2 stamp 70142
Event: message-summary
Content-Length: 0



SIP/2.0 202 Accepted
Via: SIP/2.0/UDP 172.22.0.33:38170;branch=z9hG4bK-d8754z-64e0fd2ee573d443-1---d8754z-;rport=38170
From: "SipTestAcc1000" <sip:1000@172.22.0.34>;tag=0079587c
To: "SipTestAcc1000" <sip:1000@172.22.0.34>;tag=axGJLLkPBvdL
Call-ID: MDE1OWU0ODEzMDY0NDU3N2M0NmQ0OWI1NTVkOGM5ZjE
CSeq: 3 SUBSCRIBE
Contact: <sip:1000@172.22.0.34:5060>
Expires: 0
User-Agent: FreeSWITCH-mod_sofia/1.5.2b+git~20130607T065407Z~e7fa70416d
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: timer, precondition, path, replaces
Allow-Events: talk, hold, conference, presence, dialog, line-seize, call-info, sla, include-session-description, presence.winfo, message-summary, refer
Subscription-State: terminated;reason=noresource
Content-Length: 0
2013-06-19 10:05:32.753652 [NOTICE] switch_channel.c:1027 New Channel sofia/internal/1001@172.22.0.34 [912a29fa-51db-4c87-86c1-e76eac1e2d5a]
2013-06-19 10:05:33.733181 [NOTICE] sofia.c:1786 Hangup sofia/internal/1001@172.22.0.34 [CS_NEW] [CALL_REJECTED]
2013-06-19 10:05:33.753690 [NOTICE] switch_core_session.c:1567 Session 15 (sofia/internal/1001@172.22.0.34) Ended
2013-06-19 10:05:33.753690 [NOTICE] switch_core_session.c:1571 Close Channel sofia/internal/1001@172.22.0.34 [CS_DESTROY]
06-20 09:48:23.576: V/Mjsip-Test-App||(9988): Start 
06-20 09:48:23.584: V/Mjsip-Test-App||(9988): IP: 192.168.173.176
06-20 09:48:23.584: V/Mjsip-Test-App||(9988): Stack.init
06-20 09:48:23.599: V/Mjsip-Test-App||(9988): IP: 192.168.173.176 port: 5554
06-20 09:48:23.599: V/Mjsip-Test-App||(9988): new sipProvider created
06-20 09:48:23.599: V/Mjsip-Test-App||(9988): new profile
06-20 09:48:23.599: V/Mjsip-Test-App||(9988): From: <sip:1002@172.22.0.34>
06-20 09:48:23.599: V/Mjsip-Test-App||(9988): To: <sip:1002@172.22.0.34>
06-20 09:48:23.677: V/Mjsip-Test-App||(9988): reg.register()
06-20 09:50:31.678: V/Mjsip-Test-App||(9988): Listener: onUaRegistrationFailure
06-20 09:50:31.678: V/Mjsip-Test-App||(9988): RegisterAgent: org.hsc.sip.ua.core.core.RegisterAgent@405373f0
06-20 09:50:31.678: V/Mjsip-Test-App||(9988): target: <sip:1002@172.22.0.34>
06-20 09:50:31.678: V/Mjsip-Test-App||(9988): contact: <sip:1002@172.22.0.34>
06-20 09:50:31.678: V/Mjsip-Test-App||(9988): Result: Timeout
06-20 09:50:31.755: I/System.out(9988): UA: NOT FOUND/TIMEOUT