3
public void call(Response response) {
    try {
        cseq++;

        current_process = cseq + " INVITE";
        ArrayList viaHeaders = new ArrayList();
        ViaHeader viaHeader = this.headerFactory.createViaHeader(this.ip,
                5060, "udp", null);
        viaHeaders.add(viaHeader);
        // The "Max-Forwards" header.
        MaxForwardsHeader maxForwardsHeader = this.headerFactory
                .createMaxForwardsHeader(70);
        // The "Call-Id" header.
        CallIdHeader callIdHeader = this.sipProvider.getNewCallId();
        // The "CSeq" header.
        CSeqHeader cSeqHeader = this.headerFactory.createCSeqHeader(cseq,
                "INVITE");

        Address fromAddress = addressFactory.createAddress("sip:"
                + username + '@' + server);

        Address toAddress = addressFactory.createAddress("sip:"+this.toPrefix+this.toNumber+'@'+this.toUri);

        FromHeader fromHeader = this.headerFactory.createFromHeader(
                fromAddress, String.valueOf(this.tag));
        // The "To" header.
        ToHeader toHeader = this.headerFactory.createToHeader(toAddress,
                null);

        ContentLengthHeader contentLength = this.headerFactory.createContentLengthHeader(300);
        ContentTypeHeader contentType = this.headerFactory.createContentTypeHeader("application", "sdp");

        String sdpData = "v=0\n" + 
                "o=user1 392867480 292042336 IN IP4 192.168.10.31\n" + 
                "s=-\n" + 
                "c=IN IP4 192.168.10.31\n" + 
                "t=0 0\n" + 
                "m=audio 8000 RTP/AVP 0 8 101\n" + 
                "a=rtpmap:0 PCMU/8000\n" + 
                "a=rtpmap:8 PCMA/8000\n" + 
                "a=rtpmap:101 telephone-event/8000\n" + 
                "a=sendrecv";
         byte[] contents = sdpData.getBytes();
        // this.contactHeader = this.headerFactory
        // .createContactHeader(contactAddress);

        request = this.messageFactory.createRequest("sip:"+this.toPrefix+this.toNumber+'@'
                + this.toUri + " SIP/2.0\r\n\r\n");
        request.addHeader(viaHeader);
        request.addHeader(maxForwardsHeader);
        request.addHeader(toHeader);
        request.addHeader(fromHeader);
        request.addHeader(callIdHeader);
        request.addHeader(cSeqHeader);
        request.addHeader(contactHeader);
        request.addHeader(contentLength);
        request.addHeader(contentType);
        if (response != null) {
                            retry = true;
            System.out.println("DEBUG: Response: "+response);
        }
        inviteTid = sipProvider.getNewClientTransaction(request);
        // send the request out.
        inviteTid.sendRequest();
        this.dialog = inviteTid.getDialog();
        // Send the request statelessly through the SIP provider.
        // this.sipProvider.sendRequest(request);

        // Display the message in the text area.
        logger.debug("Request sent:\n" + request.toString() + "\n\n");
    } catch (Exception e) {
        // If an error occurred, display the error.
        e.printStackTrace();
        logger.debug("Request sent failed: " + e.getMessage() + "\n");
    }
}

这是processResponse:

@Override
public void processResponse(ResponseEvent responseEvent) {
    System.out.println(responseEvent.getResponse());
    int statusCode = responseEvent.getResponse().getStatusCode();
            if (statusCode > 400 && statusCode < 410) {
    if(statusCode == 401 && current_process.contains("REGISTER")) {
        register(responseEvent.getResponse());
    }
    else if(statusCode == 401 && current_process.contains("INVITE")) {
        System.out.println("Invite 401");
    }
    else if(statusCode == 200) {
        System.out.println("Registered");
        call(null);
    }       
    else {
        System.out.println("Other code: "+ statusCode);
    }
}

我已经成功将账号注册到服务器,但是当它开始INVITE请求时,没有返回任何响应。

下面是我得到的响应(包括 REGISTER 响应),最后你会看到我发出的 INVITE 请求没有返回任何响应。

DEBUG - Request sent:
REGISTER sip:sip.dialnow.com SIP/2.0
Via: SIP/2.0/UDP 192.168.10.31:5060;branch=z9hG4bK-343133-c591d8f797a179ed25a2114311df1854
Max-Forwards: 70
To: <sip:Frax01@sip.dialnow.com>
From: <sip:Frax01@sip.dialnow.com>;tag=706572717
Call-ID: 6e49a1b2631c4b107199a8b7d9c5ee52@192.168.10.31
CSeq: 1 REGISTER
Contact: <sip:Frax01@192.168.10.31:5060;transport=UDP>
Expires: 120
Content-Length: 0




SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.10.31:5060;branch=z9hG4bK-343133-c591d8f797a179ed25a2114311df1854
From: <sip:Frax01@sip.dialnow.com>;tag=706572717
To: <sip:Frax01@sip.dialnow.com>
Contact: <sip:77.72.169.129:5060>
Call-ID: 6e49a1b2631c4b107199a8b7d9c5ee52@192.168.10.31
CSeq: 1 REGISTER
Server: (Very nice Sip Registrar/Proxy Server)
Allow: ACK,BYE,CANCEL,INVITE,REGISTER,OPTIONS,INFO,MESSAGE
WWW-Authenticate: Digest realm="sip.dialnow.com",nonce="2849852658",algorithm=MD5
Content-Length: 0


12d2ad0d764601c0573be88a3d94a2d8
8b3a241c08615fba24fb161a2a344cc9
40810f9cf3d19138dc0875dea15e3970
DEBUG - Request sent:
REGISTER sip:sip.dialnow.com SIP/2.0
Via: SIP/2.0/UDP 192.168.10.31:5060;branch=z9hG4bK-343133-3ccb8a78b8614638665f0af2a998a686
Max-Forwards: 70
To: <sip:Frax01@sip.dialnow.com>
From: <sip:Frax01@sip.dialnow.com>;tag=706572717
Call-ID: 50baef7c3a407e50d4d539a1e35cff41@192.168.10.31
CSeq: 2 REGISTER
Contact: <sip:Frax01@192.168.10.31:5060;transport=UDP>
Expires: 120
Authorization: Digest realm="sip.dialnow.com",nonce="2849852658",username="Frax01",uri="sip:sip.dialnow.com",algorithm=MD5,response="40810f9cf3d19138dc0875dea15e3970"
Content-Length: 0




SIP/2.0 100 Trying
Via: SIP/2.0/UDP 192.168.10.31:5060;branch=z9hG4bK-343133-3ccb8a78b8614638665f0af2a998a686
From: <sip:Frax01@sip.dialnow.com>;tag=706572717
To: <sip:Frax01@sip.dialnow.com>
Contact: <sip:77.72.169.129:5060>
Call-ID: 50baef7c3a407e50d4d539a1e35cff41@192.168.10.31
CSeq: 2 REGISTER
Server: (Very nice Sip Registrar/Proxy Server)
Allow: ACK,BYE,CANCEL,INVITE,REGISTER,OPTIONS,INFO,MESSAGE
Content-Length: 0


Other code: 100
SIP/2.0 200 Ok
Via: SIP/2.0/UDP 192.168.10.31:5060;branch=z9hG4bK-343133-3ccb8a78b8614638665f0af2a998a686
From: <sip:Frax01@sip.dialnow.com>;tag=706572717
To: <sip:Frax01@sip.dialnow.com>
Contact: <sip:Frax01@192.168.10.31:5060;transport=udp>;expires=120
Call-ID: 50baef7c3a407e50d4d539a1e35cff41@192.168.10.31
CSeq: 2 REGISTER
Server: (Very nice Sip Registrar/Proxy Server)
Allow: ACK,BYE,CANCEL,INVITE,REGISTER,OPTIONS,INFO,MESSAGE
Content-Length: 0


Registered
DEBUG - Request sent:
INVITE sip:6281386725319@dialnow.com SIP/2.0
Via: SIP/2.0/UDP 192.168.10.31:5060;branch=z9hG4bK-343133-e18f3eca8f76bd0a4378a12dd6e7a0d7
Max-Forwards: 70
To: <sip:6281386725319@dialnow.com>
From: <sip:Frax01@sip.dialnow.com>;tag=706572717
Call-ID: 66341e5e43e50e106a7fbf2866c0a1d3@192.168.10.31
CSeq: 3 INVITE
Contact: <sip:Frax01@192.168.10.31:5060;transport=UDP>
Content-Type: application/sdp
Content-Length: 300

如您所见,它在发送 INVITE 请求后才停止。

先感谢您,

亚当。


更多信息:

我已经尝试了 user2932861 的建议,但没有成功。我尝试使用我的公共 IP 地址,但它仍然停留在 INVITE 请求中。另外,我已经设置了我的 SDP 内容,下面是我的 SDP 内容:

        ContentTypeHeader contentType = this.headerFactory.createContentTypeHeader("application", "sdp");

        String sdpData = "v=0\n" + 
                "o=user1 392867480 292042336 IN IP4 *my IP*\n" + 
                "s=-\n" + 
                "c=IN IP4 *my IP*\n" + 
                "t=0 0\n" + 
                "m=audio 8000 RTP/AVP 0 8 101\n" + 
                "a=rtpmap:0 PCMU/8000\n" + 
                "a=rtpmap:8 PCMA/8000\n" + 
                "a=rtpmap:101 telephone-event/8000\n" + 
                "a=sendrecv";
         byte[] contents = sdpData.getBytes();

         request.setContent(contents, contentType);

注意:IP 地址已被审查。

先感谢您!


事实上,它根本没有完全返回 NO 响应,在一段时间保持沉默(不返回任何内容)之后,控制台会显示“事务超时”。知道为什么会这样吗?

4

3 回答 3

3

transaction timeout corresponds to sip timeout which should be 32s. You get this 408 answer because you received no answer. This is an automated answer generated by the stack itself, not an answer by a remote party.

Did you check your firewall settings? If you have no problem with your OS firewall, did you check your home gateway?

Are REGISTER and INVITE requests sent to the same ip address? you can check using wireshark.

yohann

于 2013-11-14T08:30:35.207 回答
0

我对你的困境的猜测:

您的联系人标题显示私人地址。尝试在此处使用可公开路由的地址。(您可以使用 STUN 来发现您的公共地址或其他方式。)如果您正在通过 B2BUA(AKA 会话边界控制器),它会为您重写这些。SIP 中的防火墙和 NAT 穿越并非易事。

此外,您的 INVITE 中有内容长度,但您有内容吗?您是否忘记设置您的 SDP 内容?

于 2013-11-12T20:32:05.300 回答
0

与其搞乱低级别的 SIP,不如尝试一个更高级别的框架,例如 SIP Servlets https://code.google.com/p/sipservlets/让您专注于您的核心业务逻辑?您甚至可以尝试使用 Amazon AMI https://aws.amazon.com/marketplace/pp/B00G9G94JW/ref=srh_res_product_title?ie=UTF8&sr=0-3&qid=1383128640630#support

于 2013-11-15T23:13:32.500 回答