2010-02-09 248 views
1

我目前在Android上使用Jain Sip,並試圖讓SIP註冊工作。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還是對話框做些額外的事情?

我是否需要創建一個套接字或某些東西來發送請求?

+1

你正在設置自己的代理? – nos 2010-02-09 12:13:39

+0

從這段代碼 - properties.setProperty( 「javax.sip.OUTBOUND_PROXY」,getLocalIpAddress()+ 「:5070」 + 「/」 \t \t \t \t + ListeningPoint.UDP); ?我應該把它設置爲服務器? – 2010-02-09 12:32:15

+0

如果你想廣告,作爲答案我會接受它作爲正確的答案 – 2010-02-10 16:48:21

回答

1

使用此代碼遠程IP地址

// 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或打印此值。

1

可能由於您的請求URI而發生。您的請求URI與來自URI的值具有相同的值。可能是你所說的IP地址是你的本地地址。儘量提供被監聽SIP端口5060