简体   繁体   English

如何用Java自动应答所有SIP呼叫

[英]How to answer all SIP Calls automatically in Java

I want automatically answer all sip calls. 我要自动接听所有的饮酒电话。 When I respond with trying or ringing, the transaction is in a proceeding state, but when I send the OK response, the transaction is in a terminated state. 当我以尝试或振铃响应时,事务处于处理状态,但是当我发送OK响应时,事务处于终止状态。 This is my code: 这是我的代码:

public void processRequest(RequestEvent requestReceivedEvent)
{
    Address contactAddress = myAddressFactory.createAddress("sip:" + myIP + ":" + myPort);
    myContactHeader = myHeaderFactory.createContactHeader(contactAddress);
    Request req = requestReceivedEvent.getRequest();
    myGUI.display("<<< " + req.toString());
    String method = req.getMethod(); //bad request type.                 
    FromHeader from = (FromHeader) req.getHeader("From");
    Response response = null;
    try
    { //Reply with OK                 
        response = myMessageFactory.createResponse(200, req);
        ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
        toHeader.setTag("888"); //Identifier, specific to your application                 
        ServerTransaction st = mySipProvider.getNewServerTransaction(req);
        response.addHeader(myContactHeader);
        st.sendResponse(response);
        System.out.println("Ok response: " + st.getState());

    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

Thanks in advance. 提前致谢。

INVITE server transactions to go terminated state after 200 OK. 200 OK之后,邀请服务器事务进入终止状态。 It's normal. 这是正常的。 Your call is answered and you shouldn't worry about it. 您的电话已接听,您不必为此担心。

(see diagram of state machine from RFC) (请参阅RFC中的状态机图)

                           |INVITE
                           |pass INV to TU
        INVITE             V send 100 if TU won't in 200ms
        send response+-----------+
            +--------|           |--------+101-199 from TU
            |        | Proceeding|        |send response
            +------->|           |<-------+
                     |           |          Transport Err.
                     |           |          Inform TU
                     |           |--------------->+
                     +-----------+                |
        300-699 from TU |     |2xx from TU        |
        send response   |     |send response      |
                        |     +------------------>+
                        |                         |
        INVITE          V          Timer G fires  |
        send response+-----------+ send response  |
            +--------|           |--------+       |
            |        | Completed |        |       |
            +------->|           |<-------+       |
                     +-----------+                |
                        |     |                   |
                    ACK |     |                   |
                    -   |     +------------------>+
                        |        Timer H fires    |
                        V        or Transport Err.|
                     +-----------+  Inform TU     |
                     |           |                |
                     | Confirmed |                |
                     |           |                |
                     +-----------+                |
                           |                      |
                           |Timer I fires         |
                           |-                     |
                           |                      |
                           V                      |
                     +-----------+                |
                     |           |                |
                     | Terminated|<---------------+
                     |           |
                     +-----------+

          Figure 7: INVITE server transaction

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM