如何在Java中自动回答所有SIP呼叫

时间:2015-02-10 13:58:41

标签: java sip jain-sip

我想自动接听所有sip电话。 当我通过尝试或响铃回应时,交易处于进行状态, 但是当我发送OK响应时,事务处于终止状态。 这是我的代码:

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();
    }
}

提前致谢。

1 个答案:

答案 0 :(得分:2)

在200 OK之后邀请服务器事务进入终止状态。这是正常的。您的电话已得到解答,您不必担心。

(参见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