1

我正在使用 Jain sip 在 android 上开发 SIP 客户端。我想用 jain-sip-presence-proxy 注册它。

我的代码:

public void register (String to) throws SipException, ParseException, InvalidArgumentException{

    //create From header
    //from sip URL and name adds
    SipURI from = addressFactory.createSipURI(sipProperties.getSipName(), sipProperties.getSipDomain());
    Address fromNameAddress = addressFactory.createAddress(from);
    fromNameAddress.setDisplayName(sipProperties.getDisplayName());


    FromHeader fromHeader = headerFactory.createFromHeader(fromNameAddress, "sipstag");//address & tag  "Bob" sips:bob@biloxi.com ;tag=a48s


    //create To header
    String username = "Server";
    String ID="server";
    String address = "10.0.2.2";


    SipURI toAddress = addressFactory.createSipURI(username, address);
    Address toNameAddress = addressFactory.createAddress(toAddress);
    toNameAddress.setDisplayName(username);//now display name is user name
    ToHeader toHeader = headerFactory.createToHeader(toNameAddress, null);

    SipURI requestURI = addressFactory.createSipURI(username, address);
    requestURI.setTransportParam("udp");

    //via header
    ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
    ViaHeader viaHeader = headerFactory.createViaHeader(sipProperties.getHostIp(), sipProperties.getISipPort(), "udp", null);
    viaHeaders.add(viaHeader);

    //create call id
    CallIdHeader callIdHeader = sipProvider.getNewCallId();
    //Cseq
    CSeqHeader cSeqHeader = headerFactory.createCSeqHeader(1l, Request.REGISTER);
    //MaxForwards
    MaxForwardsHeader maxForwards = headerFactory.createMaxForwardsHeader(70);

    Request request = messageFactory.createRequest(requestURI, Request.REGISTER, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards);

    SipURI contactURI = addressFactory.createSipURI(sipProperties.getSipName(), sipProperties.getSipDomain());
    contactURI.setPort(sipProperties.getISipPort());
    Address contactAddress = addressFactory.createAddress(contactURI);
    contactAddress.setDisplayName(sipProperties.getDisplayName());
    ContactHeader contactHeader = headerFactory.createContactHeader(contactAddress);
    request.addHeader(contactHeader);


    sipProvider.sendRequest(request);
    log.logMessage("send request is OK");

}   

错误信息是:

DEBUG - gov.nist.javax.sip.stack.UDPMessageChannel.run(UDPMessageChannel.java:241) [error message Via: SIP/2.0/UDP 10.0.2.15:8888;branch=sipstag:9890152798caf4a47bda2f6a43187186@10.0.2.15:1:register:10.0.2.15:8888

ID expected]
ERROR - Via: SIP/2.0/UDP 10.0.2.15:8888;branch=sipstag:9890152798caf4a47bda2f6a43187186@10.0.2.15:1:register:10.0.2.15:8888

ID expected
java.text.ParseException: Via: SIP/2.0/UDP 10.0.2.15:8888;branch=sipstag:9890152798caf4a47bda2f6a43187186@10.0.2.15:1:register:10.0.2.15:8888

ID expected
    at gov.nist.core.LexerCore.match(LexerCore.java:190)
    at gov.nist.javax.sip.parser.ViaParser.parseVia(ViaParser.java:32)
    at gov.nist.javax.sip.parser.ViaParser.parse(ViaParser.java:186)
    at gov.nist.javax.sip.parser.StringMsgParser.parseMessage(StringMsgParser.java:555)
    at gov.nist.javax.sip.parser.StringMsgParser.parseSIPMessage(StringMsgParser.java:327)
    at gov.nist.javax.sip.stack.UDPMessageChannel.run(UDPMessageChannel.java:234)
    at java.lang.Thread.run(Thread.java:662)
DEBUG - gov.nist.javax.sip.stack.UDPMessageChannel.run(UDPMessageChannel.java:247) [REGISTER sip:Server@10.0.2.2;transport=udp SIP/2.0
Call-ID: 9890152798caf4a47bda2f6a43187186@10.0.2.15
CSeq: 1 REGISTER
From: "cy" <sip:cy@mydomain.com>;tag=sipstag
To: "Server" <sip:Server@10.0.2.2>
Via: SIP/2.0/UDP 10.0.2.15:8888;branch=sipstag:9890152798caf4a47bda2f6a43187186@10.0.2.15:1:register:10.0.2.15:8888
Max-Forwards: 70
Contact: "cy" <sip:cy@mydomain.com:8888>
Content-Length: 0

]

你能帮助我吗?

4

1 回答 1

1

问题已经解决了。

分支设置为"z9hG4bKbranch1",客户端可以成功注册代理服务器。

ViaHeader viaHeader = headerFactory.createViaHeader(sipProperties.getHostIp(), sipProperties.getISipPort(), "udp", "z9hG4bKbranch1");
于 2011-06-26T01:48:40.403 回答