实施取消请求

Implement cancelRequest

我正在为正在进行的通话实施取消请求。会话建立后,我尝试发送请求。取消功能在我第一次实现它时有效,但现在它说交易存在。我该如何解决?

else if(currentREsponse.equals("Session Progress")){
            System.out.println("------------------- Status Code: "+ statusCode+ "--------------------------");
            System.out.println(responseEvent.getResponse());
            try {

                Request cancelRequest;
                cancelRequest = inviteTid.createCancel();
                ClientTransaction canceltid = sipProvider.getNewClientTransaction(cancelRequest);
                canceltid.sendRequest();
                System.out.println("Cancel Requst:" + cancelRequest);
            } catch (SipException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 
        }

回复:

-----------StatusCode:100----------------------------
-----------currentREsponse:Trying----------------------------
------------------- Status Code: 100--------------------------
SIP/2.0 100 Trying
Via: SIP/2.0/UDP localIP:52216;branch=z9hG4bK-353435-03dc537ef691bb00e1e5512b034ea431;received=localIP;rport=52216
From: <sip:username@sipIP>;tag=-2016245219
To: <sip:86940160@sipIP>
Call-ID: fab08b0be8c74b236c9eced419dec3ae@localIP
CSeq: 5 INVITE
Server: Asterisk PBX 10.5.1
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY,INFO,PUBLISH
Supported: replaces,timer
Contact: <sip:86940160@sipIP:5060>
Content-Length: 0


------------------- Phone is RINGING hangup --------------------------


Request OPTIONSreceived at stackwith server transaction idnull
-----------StatusCode:183----------------------------
-----------currentREsponse:Session Progress----------------------------
------------------- Status Code: 183--------------------------
SIP/2.0 183 Session Progress
Via: SIP/2.0/UDP localIP:52216;branch=z9hG4bK-353435-03dc537ef691bb00e1e5512b034ea431;received=localIP;rport=52216
From: <sip:username@sipIP>;tag=-2016245219
To: <sip:86940160@sipIP>;tag=as06d748b5
Call-ID: fab08b0be8c74b236c9eced419dec3ae@localIP
CSeq: 5 INVITE
Server: Asterisk PBX 10.5.1
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY,INFO,PUBLISH
Supported: replaces,timer
Contact: <sip:86940160@sipIP:5060>
Content-Type: application/sdp
Content-Length: 254

v=0
o=root 16865513 16865513 IN IP4 sipIP
s=Asterisk PBX 10.5.1
c=IN IP4 sipIP
t=0 0
m=audio 16188 RTP/AVP 8 101
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=silenceSupp:off - - - -
a=ptime:20
a=sendrecv

Cancel Requst:CANCEL sip:86940160@sipIP SIP/2.0
Call-ID: fab08b0be8c74b236c9eced419dec3ae@localIP
To: <sip:86940160@sipIP>
CSeq: 5 CANCEL
From: <sip:username@sipIP>;tag=-2016245219
Via: SIP/2.0/UDP localIP:52216;rport;branch=z9hG4bK-353435-32ce00c8a1c2efc96caa44a14bf3b910
Max-Forwards: 70
Content-Length: 0




Request OPTIONSreceived at stackwith server transaction idnull
-----------StatusCode:401----------------------------
-----------currentREsponse:Unauthorized----------------------------
---------------UNAUTHORIZED--------SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP localIP:52216;branch=z9hG4bK-353435-32ce00c8a1c2efc96caa44a14bf3b910;received=localIP;rport=52216
From: <sip:username@sipIP>;tag=-2016245219
To: <sip:86940160@sipIP>;tag=as647be936
Call-ID: fab08b0be8c74b236c9eced419dec3ae@localIP
CSeq: 5 INVITE
Server: Asterisk PBX 10.5.1
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY,INFO,PUBLISH
Supported: replaces,timer
WWW-Authenticate: Digest algorithm=MD5,realm="xyz.com",nonce="69e1f4c2"
Content-Length: 0


-----------StatusCode:481----------------------------
-----------currentREsponse:Call/Transaction Does Not Exist----------------------------
-------------------Status Code: 481 ----------------------
SIP/2.0 481 Call/Transaction Does Not Exist
Via: SIP/2.0/UDP 10.99.136.131:52216;branch=z9hG4bK-353435-32ce00c8a1c2efc96caa44a14bf3b910;received=10.99.136.131;rport=52216
From: <sip:username@sipIP>;tag=-2016245219
To: <sip:86940160@sipIP>;tag=as647be936
Call-ID: fab08b0be8c74b236c9eced419dec3ae@10.99.136.131
CSeq: 5 CANCEL
Server: Asterisk PBX 10.5.1
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY,INFO,PUBLISH
Supported: replaces,timer
Content-Length: 0


Request OPTIONSreceived at stackwith server transaction idnull

处理响应

public void processResponse(ResponseEvent responseEvent) {
        // TODO Auto-generated method stub
        int statusCode = responseEvent.getResponse().getStatusCode();
        String currentResponse = responseEvent.getResponse().getReasonPhrase();
//      System.out.println("-----------StatusCode:"+ statusCode+"----------------------------");
//      System.out.println("-----------currentREsponse:"+ currentResponse+"----------------------------");
        CSeqHeader cseqtemp = (CSeqHeader) responseEvent.getResponse().getHeader(CSeqHeader.NAME);          
//      System.out.println(responseEvent.getResponse().toString());

        System.out.println("................cseq" + cseqtemp);
        if(cseqtemp.getMethod().equals(Request.REGISTER)){
            processRegisterResponse(responseEvent);
        }else if(cseqtemp.getMethod().equals(Request.INVITE)){

            countInviteResponse ++;
            System.out.println(".....countInviteResponse: "+ countInviteResponse+" ......" );

            if(countInviteResponse == 6){
                System.out.println(responseEvent.getResponse());
//              functions.cancel(responseEvent.getResponse());
            }
            try {
                processInviteResponse(responseEvent);
            } catch (SipException | InvalidArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        else {
            System.out.println("-------------------Status Code: "+ statusCode+" ----------------------");
            System.out.println(responseEvent.getResponse().toString());
        }

ProcessInvite 响应:

private void processInviteResponse(ResponseEvent responseReceivedEvent) throws SipException, InvalidArgumentException {
        int statusCode = responseReceivedEvent.getResponse().getStatusCode();
        String currentResponse = responseReceivedEvent.getResponse().getReasonPhrase();
        Response response = responseReceivedEvent.getResponse();
        ClientTransaction tid = responseReceivedEvent.getClientTransaction();
        CSeqHeader cseqtemp = (CSeqHeader) response.getHeader(CSeqHeader.NAME);
        if(statusCode> 400 && statusCode <410){
            if((statusCode ==401 && cseqtemp.getMethod().equals(Request.INVITE))
                    || response.getStatusCode() == Response.PROXY_AUTHENTICATION_REQUIRED){
                System.out.println(responseReceivedEvent.getResponse().toString());
//              if(functions.cseq<4){

                    System.out.println("------------------Invite 401--------------------\n");

                    AuthenticationHelper authenticationHelper = 
                            ((SipStackExt) functions.sipStack).getAuthenticationHelper(new AccountManagerImpl(), functions.headerFactory);
                    try {
                        functions.inviteTid = authenticationHelper.handleChallenge(response, functions.inviteTid, functions.sipProvider, 5);
                        functions.inviteTid.sendRequest();
                        System.out.println("/n" + functions.inviteTid.getRequest());
                    } catch (NullPointerException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (SipException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
//                  functions.call(responseReceivedEvent.getResponse());
//              }
            }
        }else if(statusCode == 200){
            try {
                System.out.println(responseReceivedEvent.getResponse().toString());

                response = (Response) responseReceivedEvent.getResponse();
                tid = responseReceivedEvent.getClientTransaction();
                CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME);     
                Dialog dialog = responseReceivedEvent.getDialog();


                if (tid == null) {
                    // RFC3261: MUST respond to every 2xx
                    if (ackRequest!=null && dialog!=null) {
                        System.out.println("re-sending ACK");
                        dialog.sendAck(ackRequest);
                    }
                    return;
                }

                if (response.getStatusCode() == Response.OK) {
                    System.out.println("Dialog after 200 OK  " + dialog);
                    System.out.println("Dialog State after 200 OK  " + dialog.getState());
                    ackRequest = dialog.createAck(cseq.getSeqNumber() );
                    System.out.println("Sending ACK");
                    dialog.sendAck(ackRequest);
                }



                }
             catch (InvalidArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SipException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }else if(responseReceivedEvent.getResponse().getReasonPhrase().equals("Trying")){
            System.out.println("------------------- Status Code: "+ statusCode+ "--------------------------");
            System.out.println(responseReceivedEvent.getResponse());


        }else if(responseReceivedEvent.getResponse().getReasonPhrase().equals("Ringing")){
            System.out.println("------------------- Status Code: "+ statusCode+ "--------------------------");
            System.out.println(responseReceivedEvent.getResponse());
            System.out.println("------------------- Phone is RINGING --------------------------");


        }else if(responseReceivedEvent.getResponse().getReasonPhrase().equals("Session Progress")){
            System.out.println("------------------- Status Code: "+ statusCode+ "--------------------------");
            System.out.println(responseReceivedEvent.getResponse());
//          functions.cancel(response);

            Request cancelRequest= responseReceivedEvent.getClientTransaction().createCancel();

            functions.sipProvider.sendRequest(cancelRequest);
            System.out.println(cancelRequest.toString());
        }else {
            System.out.println("------------------- Status Code: "+ statusCode+ "--------------------------");
            System.out.println(responseReceivedEvent.getResponse());
        }


    }

邀请:

public void call(Response response) {
        try {
            Request request;
            cseq++;
            String callee = "86940160";
//          String callee = "160";
            current_process = cseq + "INVITE";
            ArrayList viaHeaders = new ArrayList();
            ViaHeader viaHeader = headerFactory.createViaHeader(localIP,
                    rport, "udp", null);
            viaHeader.setRPort();
            viaHeaders.add(viaHeader);
            // The "Max-Forwards" header.
            MaxForwardsHeader maxForwardsHeader = headerFactory.createMaxForwardsHeader(70);
            // The "Call-Id" header.
            CallIdHeader callIdHeader;

            if(!retry){
                callIdHeader = this.sipProvider.getNewCallId();
                callIdHeaderinit = callIdHeader;
            }else{
                callIdHeader = callIdHeaderinit;
            }

            // The "CSeq" header.
            CSeqHeader cSeqHeader = headerFactory.createCSeqHeader(cseq, Request.INVITE);

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

            Address toAddress = addressFactory.createAddress("sip:"+callee+'@'+sipIP);

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

         // Create the contact address used for all SIP messages.
            contactAddress = addressFactory.createAddress("sip:" + username + "@"+ localIP +":"+rport+ ";"+ "transport=UDP");

            // Create the contact header used for all SIP messages.
            contactHeader = headerFactory.createContactHeader(contactAddress);

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

            String sdpData = "v=0\n" + 
                    "o=user1 795808818 480847547 IN IP4 "+localIP+"\n" + 
                    "s=-\n" + 
                    "c=IN IP4 "+localIP+"\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);

             URI requestURI = addressFactory.createURI("sip:"
                    +callee+ '@'+ server); 

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

            request.setContent(contents, contentType);

            request.addHeader(contactHeader);
            request.addHeader(contentLength);

            if (response != null) {
                AuthorizationHeader authHeader = null;

                if(retry){
                    authHeader = getAuthorizationHeader();
                    retry = false;
                }else{
                    authHeader = makeAuthHeader(headerFactory, response, request, username, password);
                    retry = true;
                }
                request.addHeader(authHeader);
//              AuthenticationHelper authenticationHelper = 
//                      ((SipStackExt) sipStack).getAuthenticationHelper(new AccountManagerImpl(), headerFactory);
//              try {
//                  inviteTid = authenticationHelper.handleChallenge(response, tid, sipProvider, 5);
//                  inviteTid.sendRequest();
//              } catch (NullPointerException e) {
//                  // TODO Auto-generated catch block
//                  e.printStackTrace();
//              } catch (SipException e) {
//                  // TODO Auto-generated catch block
//                  e.printStackTrace();
//              }
            }

//          ExpiresHeader expiresHeader = headerFactory.createExpiresHeader(1);
//   
//          request.addHeader(expiresHeader);

//          test listener =this;
            if (response != null) {
                boolean retry = true;
//              System.out.println("DEBUG: Response: "+response);

            }
            inviteTid = sipProvider.getNewClientTransaction(request);


            if(dialog!= null && logger.isDebugEnabled()){
                logger.debug("Obtain dialog from ClientTransaction: automatic dialog support on");
//              System.out.println("Obtain dialog from ClientTransaction: automatic dialog support on");
            }
            if(dialog == null){
                //Automatic Dialog support turned off

                dialog = sipProvider.getNewDialog(inviteTid);

            }
            System.out.println("Dialog: created" + dialog);
            // send the request out.
            inviteTid.sendRequest();

            dialog = inviteTid.getDialog();
//          System.out.println("Dialog:" + dialog);

            // Send the request statelessly through the SIP provider.
            // this.sipProvider.sendRequest(request);
            System.out.println(request.toString());
            // Display the message in the text area.
            logger.debug("Request sent:\n" + "\n\n");
        } catch (Exception e) {
            // If an error occurred, display the error.
            e.printStackTrace();
            logger.debug("Request sent failed: " + e.getMessage() + "\n");
        }
    }

回复:

REGISTER sip:sipIP SIP/2.0
Call-ID: cdf4ef0fa1a145b1b07b632797f53fdb@localIP
CSeq: 1 REGISTER
From: <sip:username@sipIP>;tag=-1436906198
To: <sip:username@sipIP>
Via: SIP/2.0/UDP localIP:52216;rport;branch=z9hG4bK-3230-3d42d8c86f8aa3d6d0194a4846511464
Max-Forwards: 70
Contact: <sip:username@localIP:52216;transport=UDP>
Content-Length: 0


log4j:WARN No appenders could be found for logger (test).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
................cseqCSeq: 1 REGISTER

SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP localIP:52216;branch=z9hG4bK-3230-3d42d8c86f8aa3d6d0194a4846511464;received=localIP;rport=52216
From: <sip:username@sipIP>;tag=-1436906198
To: <sip:username@sipIP>;tag=as24ab6bcf
Call-ID: cdf4ef0fa1a145b1b07b632797f53fdb@localIP
CSeq: 1 REGISTER
Server: Asterisk PBX 10.5.1
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY,INFO,PUBLISH
Supported: replaces,timer
WWW-Authenticate: Digest algorithm=MD5,realm="xyz.com",nonce="6ac7ff34"
Content-Length: 0


REGISTER sip:sipIP SIP/2.0
Call-ID: cdf4ef0fa1a145b1b07b632797f53fdb@localIP
CSeq: 2 REGISTER
From: <sip:username@sipIP>;tag=-1436906198
To: <sip:username@sipIP>
Via: SIP/2.0/UDP localIP:52216;rport;branch=z9hG4bK-3230-a94c094a3aacfc40d0455de777b0ae26
Max-Forwards: 70
Contact: <sip:username@localIP:52216;transport=UDP>
Authorization: Digest username="username",realm="xyz.com",nonce="6ac7ff34",uri="sip:sipIP",algorithm=MD5,response="53231e4a2cd26604d8d2bc867b0e43e9"
Content-Length: 0


................cseqCSeq: 2 REGISTER

---------------------------Registered: 200--------------------

SIP/2.0 200 OK
Via: SIP/2.0/UDP localIP:52216;branch=z9hG4bK-3230-a94c094a3aacfc40d0455de777b0ae26;received=localIP;rport=52216
From: <sip:username@sipIP>;tag=-1436906198
To: <sip:username@sipIP>;tag=as24ab6bcf
Call-ID: cdf4ef0fa1a145b1b07b632797f53fdb@localIP
CSeq: 2 REGISTER
Server: Asterisk PBX 10.5.1
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY,INFO,PUBLISH
Supported: replaces,timer
Expires: 240
Contact: <sip:username@localIP:52216;transport=UDP>;expires=240
Date: Thu, 30 Apr 2015 14:46:46 GMT
Content-Length: 0


Dialog: createdgov.nist.javax.sip.stack.SIPDialog@79f65165
INVITE sip:86940160@sipIP SIP/2.0
Call-ID: cdf4ef0fa1a145b1b07b632797f53fdb@localIP
CSeq: 3 INVITE
From: <sip:username@sipIP>;tag=-1436906198
To: <sip:86940160@sipIP>
Via: SIP/2.0/UDP localIP:52216;rport;branch=z9hG4bK-3230-c5512f65af9890c0798f1e5757ef1c57
Max-Forwards: 70
Content-Type: application/sdp
Contact: <sip:username@localIP:52216;transport=UDP>
Authorization: Digest username="username",realm="xyz.com",nonce="6ac7ff34",uri="sip:sipIP",algorithm=MD5,response="53231e4a2cd26604d8d2bc867b0e43e9"
Content-Length: 211

v=0
o=user1 795808818 480847547 IN IP4 localIP
s=-
c=IN IP4 localIP
t=0 0
m=audio 8000 RTP/AVP 0 8 101
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=sendrecv


Request OPTIONSreceived at stackwith server transaction idnull


Request OPTIONSreceived at stackwith server transaction idnull
................cseqCSeq: 3 INVITE

.....countInviteResponse: 1 ......
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP localIP:52216;branch=z9hG4bK-3230-c5512f65af9890c0798f1e5757ef1c57;received=localIP;rport=52216
From: <sip:username@sipIP>;tag=-1436906198
To: <sip:86940160@sipIP>;tag=as43ee81b7
Call-ID: cdf4ef0fa1a145b1b07b632797f53fdb@localIP
CSeq: 3 INVITE
Server: Asterisk PBX 10.5.1
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY,INFO,PUBLISH
Supported: replaces,timer
WWW-Authenticate: Digest algorithm=MD5,realm="xyz.com",nonce="6ad3bcf0"
Content-Length: 0

删除标签后的响应:

------------------Invite 401--------------------

/nINVITE sip:86940160@sipIP:5060;maddr=sipIP SIP/2.0
Call-ID: 7128d7fc7109b0c1293dce9f6b2b9c7b@localIP.131
CSeq: 4 INVITE
From: <sip:username@sipIP>;tag=-515507368
To: <sip:86940160@sipIP>
Via: SIP/2.0/UDP localIP.131:52216;rport;branch=z9hG4bK-313339-453b043ba57ac51c5293cf17f8823071
Max-Forwards: 70
Content-Type: application/sdp
Contact: <sip:username@localIP.131:52216;transport=UDP>
Authorization: Digest username="username",realm="xyz.com",nonce="3cdd5016",uri="sip:86940160@sipIP:5060;maddr=sipIP",response="38b50cad69f74ba89fd63f78a1968acc",algorithm=MD5
Content-Length: 211

v=0
o=user1 795808818 480847547 IN IP4 localIP.131
s=-
c=IN IP4 localIP.131
t=0 0
m=audio 8000 RTP/AVP 0 8 101
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=sendrecv


Request OPTIONSreceived at stackwith server transaction idnull
................cseqCSeq: 4 INVITE

.....countInviteResponse: 2 ......
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP localIP.131:52216;branch=z9hG4bK-313339-453b043ba57ac51c5293cf17f8823071;received=localIP.131;rport=52216
From: <sip:username@sipIP>;tag=-515507368
To: <sip:86940160@sipIP>;tag=as5f585fd4
Call-ID: 7128d7fc7109b0c1293dce9f6b2b9c7b@localIP.131
CSeq: 4 INVITE
Server: Asterisk PBX 10.5.1
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY,INFO,PUBLISH
Supported: replaces,timer
WWW-Authenticate: Digest algorithm=MD5,realm="xyz.com",nonce="6aa75c9f"
Content-Length: 0


------------------Invite 401--------------------

/nINVITE sip:86940160@sipIP:5060;maddr=sipIP SIP/2.0
Call-ID: 7128d7fc7109b0c1293dce9f6b2b9c7b@localIP.131
CSeq: 5 INVITE
From: <sip:username@sipIP>;tag=-515507368
To: <sip:86940160@sipIP>
Via: SIP/2.0/UDP localIP.131:52216;rport;branch=z9hG4bK-313339-5ed3ab3afc3b791c0af19470ae58813d
Max-Forwards: 70
Content-Type: application/sdp
Contact: <sip:username@localIP.131:52216;transport=UDP>
Authorization: Digest username="username",realm="xyz.com",nonce="6aa75c9f",uri="sip:86940160@sipIP:5060;maddr=sipIP",response="092fc083a66f19b5b995c8cbc8d5a8bc",algorithm=MD5
Content-Length: 211

v=0
o=user1 795808818 480847547 IN IP4 localIP.131
s=-
c=IN IP4 localIP.131
t=0 0
m=audio 8000 RTP/AVP 0 8 101
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=sendrecv
................cseqCSeq: 5 INVITE

.....countInviteResponse: 3 ......
------------------- Status Code: 100--------------------------
SIP/2.0 100 Trying
Via: SIP/2.0/UDP localIP.131:52216;branch=z9hG4bK-313339-5ed3ab3afc3b791c0af19470ae58813d;received=localIP.131;rport=52216
From: <sip:username@sipIP>;tag=-515507368
To: <sip:86940160@sipIP>
Call-ID: 7128d7fc7109b0c1293dce9f6b2b9c7b@localIP.131
CSeq: 5 INVITE
Server: Asterisk PBX 10.5.1
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY,INFO,PUBLISH
Supported: replaces,timer
Contact: <sip:86940160@sipIP:5060>
Content-Length: 0


................cseqCSeq: 5 INVITE

.....countInviteResponse: 4 ......
------------------- Status Code: 183--------------------------
SIP/2.0 183 Session Progress
Via: SIP/2.0/UDP localIP.131:52216;branch=z9hG4bK-313339-5ed3ab3afc3b791c0af19470ae58813d;received=localIP.131;rport=52216
From: <sip:username@sipIP>;tag=-515507368
To: <sip:86940160@sipIP>;tag=as7fc2a07d
Call-ID: 7128d7fc7109b0c1293dce9f6b2b9c7b@localIP.131
CSeq: 5 INVITE
Server: Asterisk PBX 10.5.1
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY,INFO,PUBLISH
Supported: replaces,timer
Contact: <sip:86940160@sipIP:5060>
Content-Type: application/sdp
Content-Length: 256

v=0
o=root 163700690 163700690 IN IP4 sipIP
s=Asterisk PBX 10.5.1
c=IN IP4 sipIP
t=0 0
m=audio 25036 RTP/AVP 8 101
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=silenceSupp:off - - - -
a=ptime:20
a=sendrecv

Invite ID:z9hG4bK-313339-5ed3ab3afc3b791c0af19470ae58813d
CANCEL sip:86940160@sipIP:5060;maddr=sipIP SIP/2.0
Call-ID: 7128d7fc7109b0c1293dce9f6b2b9c7b@localIP.131
To: <sip:86940160@sipIP>
CSeq: 5 CANCEL
From: <sip:username@sipIP>;tag=-515507368
Via: SIP/2.0/UDP localIP.131:52216;rport;branch=z9hG4bK-313339-5ed3ab3afc3b791c0af19470ae58813d
Max-Forwards: 70
Content-Length: 0


................cseqCSeq: 5 CANCEL

-------------------Status Code: 481 ----------------------
SIP/2.0 481 Call/Transaction Does Not Exist
Via: SIP/2.0/UDP localIP.131:52216;branch=z9hG4bK-313339-5ed3ab3afc3b791c0af19470ae58813d;received=localIP.131;rport=52216
From: <sip:username@sipIP>;tag=-515507368
To: <sip:86940160@sipIP>;tag=as23aeabf5
Call-ID: 7128d7fc7109b0c1293dce9f6b2b9c7b@localIP.131
CSeq: 5 CANCEL
Server: Asterisk PBX 10.5.1
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY,INFO,PUBLISH
Supported: replaces,timer
Content-Length: 0

INVITE 交易 ID 与 CANCEL 交易 ID 不同。邀请

z9hG4bK-353435-03dc537ef691bb00e1e5512b034ea431

取消是

z9hG4bK-353435-32ce00c8a1c2efc96caa44a14bf3b910

它们应该是一样的。

取消的正确方法是使用原始邀请交易并使用提供商

cancelRequest = inviteClientTransaction.createCancel(); sipProvider.sendRequest(cancelRequest);

我添加了一个 5 秒的线程,现在可以使用了。防火墙是如何延迟交易的。