Android Jain Sip - Sip 注册?

Posted

技术标签:

【中文标题】Android Jain Sip - Sip 注册?【英文标题】:Android Jain Sip - Sip Registration? 【发布时间】:2011-01-14 18:57:06 【问题描述】:

我目前在 android 上使用 Jain Sip,我正在尝试让 SIP 注册工作。

我可以将注册 SIP 消息放在一起,但是在发送消息之后,它似乎只是被发送回我的应用程序,并且我的应用程序 processRequest() 方法正在运行。

这是我正在使用的代码:

 public void init(TextView tv) throws Exception 
    SipFactory sipFactory = null;
    sipStack = null;
    sipFactory = SipFactory.getInstance();
    sipFactory.setPathName("gov.nist");
    Properties properties = new Properties();
    properties.setProperty("javax.sip.OUTBOUND_PROXY", getLocalIpAddress()+":8002" + "/"
            + ListeningPoint.UDP);
    properties.setProperty("javax.sip.STACK_NAME", "Sip Test");
    // Create SipStack object
    sipStack = sipFactory.createSipStack(properties);
    tv.setText("sipStack = " + sipStack);
    headerFactory = sipFactory.createHeaderFactory();
    addressFactory = sipFactory.createAddressFactory();
    messageFactory = sipFactory.createMessageFactory();
    lp = sipStack.createListeningPoint(getLocalIpAddress(),
            8002, ListeningPoint.UDP);


    sipProvider = sipStack.createSipProvider(lp);
    sipOnOffFlag = true;
    tv.append("\n jain sip stack started on " + getLocalIpAddress() + ":" + myPort + "/" + ListeningPoint.UDP);
    sipProvider.addSipListener(this);   


    String fromName = "019078020";
    String fromSipAddress = "216.234.148.28";
    String fromDisplayName = "Donal";

    String toSipAddress = "216.234.148.28";
    String toUser = "16784732970";
    String toDisplayName = "Server";

    // create >From Header
    SipURI fromAddress = addressFactory.createSipURI(fromName,
            getLocalIpAddress());

    Address fromNameAddress = addressFactory.createAddress(fromAddress);
    fromNameAddress.setDisplayName(fromDisplayName);
    FromHeader fromHeader = headerFactory.createFromHeader(
            fromNameAddress, null);

    // create To Header
    SipURI toAddress = addressFactory
            .createSipURI(toUser, toSipAddress);
    Address toNameAddress = addressFactory.createAddress(toAddress);
    toNameAddress.setDisplayName(toDisplayName);
    ToHeader toHeader = headerFactory.createToHeader(toNameAddress,
            null);

    // create Request URI
    SipURI requestURI = addressFactory.createSipURI(toUser,
            "216.234.148.28");

    // Create ViaHeaders

    List<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
    String ipAddress = lp.getIPAddress();
    ViaHeader viaHeader = headerFactory.createViaHeader(ipAddress,
            lp.getPort(),
            lp.getTransport(), null);

    // add via headers
    viaHeaders.add(viaHeader);

    // Create ContentTypeHeader
    ContentTypeHeader contentTypeHeader = headerFactory
            .createContentTypeHeader("application", "sdp");

    // Create a new CallId header
    CallIdHeader callIdHeader = sipProvider.getNewCallId();

    // Create a new Cseq header
    CSeqHeader cSeqHeader = headerFactory.createCSeqHeader(1L,
            Request.REGISTER);

    // Create a new MaxForwardsHeader
    MaxForwardsHeader maxForwards = headerFactory
            .createMaxForwardsHeader(70);

    // Create the request.
    Request request = messageFactory.createRequest(requestURI,
            Request.REGISTER, callIdHeader, cSeqHeader, fromHeader,
            toHeader, viaHeaders, maxForwards);
    // Create contact headers

    SipURI contactUrl = addressFactory.createSipURI(fromName, getLocalIpAddress());
    contactUrl.setPort(8002);
    contactUrl.setLrParam();

    // Create the contact name address.
    SipURI contactURI = addressFactory.createSipURI(fromName, getLocalIpAddress());
    contactURI.setPort(sipProvider.getListeningPoint(lp.getTransport())
            .getPort());

    Address contactAddress = addressFactory.createAddress(contactURI);

    // Add the contact address.
    contactAddress.setDisplayName(fromName);

    contactHeader = headerFactory.createContactHeader(contactAddress);
    request.addHeader(contactHeader);

    // You can add extension headers of your own making
    // to the outgoing SIP request.
    // Add the extension header.
    Header extensionHeader = headerFactory.createHeader("Expires",
        "0");
    request.addHeader(extensionHeader);


    Log.d("SIP", "" + request.toString());
    // Create the client transaction.
    registerTid = sipProvider.getNewClientTransaction(request);

    // send the request out.
    registerTid.sendRequest();

    dialog = registerTid.getDialog();

所以消息构建正常,但是当 sendRequest() 运行时,它似乎没有发送到服务器,而是返回到我的应用程序,并且运行应用程序 processRequest 方法。

我应该对inviteTid 或对话框做一些额外的事情吗?

我需要创建一个套接字或其他东西来发送请求吗?

【问题讨论】:

您将代理设置为您自己? 来自这段代码 - properties.setProperty("javax.sip.OUTBOUND_PROXY", getLocalIpAddress()+":5070" + "/" + ListeningPoint.UDP); ?我应该将其设置为服务器吗? 如果您想将其作为答案,我将接受它作为正确答案 【参考方案1】:

使用此代码

// create Request URI
SipURI requestURI = addressFactory.createSipURI(toUser,
        "216.234.148.28");

您的 SIP 消息 URI 将如下所示

REGISTER sip:216.234.148.28 SIP/2.0

现在“216.234.148.28”是目标 IP 地址(您的请求将被发送到该地址)。

从线

String fromName = "019078020";
String fromSipAddress = "216.234.148.28";
String fromDisplayName = "Donal";

看起来“216.234.148.28”是您的 IP 地址。因此,您既是源又是目标。尝试获取系统的 pcap 或打印此值。

【讨论】:

【参考方案2】:

这可能是由于您的请求 URI 而发生的。您的请求 URI 与您的 from URI 具有相同的值。您所说的 IP 地址可能是您的本地地址。尝试提供一个在 5060 端口上监听 SIP 的远程 IP 地址。

【讨论】:

以上是关于Android Jain Sip - Sip 注册?的主要内容,如果未能解决你的问题,请参考以下文章

JAIN SIP setPathName()

如何添加 JAIN SIP?

下载 JAIN SIP

基于 Java 的 SIP 端点

如何在 SIP/SDP 呼叫中启动 RTP 流

SIP 注册侦听器未触发