使用NIST JAIN SIP API发送SIP请求时出错

时间:2011-04-06 12:48:47

标签: sip jain-sip

我正在尝试使用NIST的JAIN SIP API实现发送REGISTER SIP请求。

首先,我给出了我的SipController类的数据成员的声明:

private int port;
private long cseq = Math.abs(numberGenerator.nextInt());
private MessageFactory messageFactory;
private AddressFactory addressFactory;
private HeaderFactory headerFactory;
private SipStack sipStack;
private SipProvider sipProvider;

以下是发送请求的代码:

public void register(String aor,String serverAddress) throws ParseException,InvalidArgumentException,SipException  
    {  
        Address addressOfRecordObj = addressFactory.createAddress(aor);  
        ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>(1);  
        try  
        {  
            viaHeaders.add(headerFactory.createViaHeader(InetAddress.getLocalHost().getHostAddress(),port,"udp",getNewBranch()));  
        }  
        catch (UnknownHostException e)  
        {  
            e.printStackTrace();  
        }  
        Request request = messageFactory.createRequest(  
                ....addressFactory.createURI(serverAddress),  
                ...."REGISTER",sipProvider.getNewCallId(),  
                ....headerFactory.createCSeqHeader(cseq++,"REGISTER"),  
                ....headerFactory.createFromHeader(addressOfRecordObj,Integer.toString(Math.abs(numberGenerator.nextInt()))),  
                ....headerFactory.createToHeader(addressOfRecordObj,null),  
                ....viaHeaders,  
                ....headerFactory.createMaxForwardsHeader(70));  
        request.addHeader(headerFactory.createContactHeader(addressFactory.createAddress("sip:127.0.0.1:"+port)));  
        log(">> "+request);  
        sipProvider.sendRequest(request);  
}

我使用语句

调用此方法
sipController.register("sip:user@domain.com","sip:127.0.0.1:5061");

数据成员端口的值为5060。

我要做的是向我的计算机上运行的另一个应用程序发送请求,该应用程序正在侦听端口5061.此应用程序是我发送请求的同一程序的另一个实例。

当我调用SipProvider类的sendRequest()方法时,我得到一个javax.sip.SipException异常,并显示消息“发送请求时发生IO异常”。此异常包含java.net.BindException作为其原因,并带有消息“无法分配请求的地址:数据报发送失败”。

这是堆栈跟踪:

javax.sip.SipException: IO Exception occured while Sending Request
    at gov.nist.javax.sip.SipProviderImpl.sendRequest(SipProviderImpl.java:723)
    at siptest.SipController.register(SipController.java:133)
    at siptest.SipTestGuiFrontend$SendButtonListener.actionPerformed(SipTestGuiFrontend.java:213)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.net.BindException: Cannot assign requested address: Datagram send failed
    at java.net.PlainDatagramSocketImpl.send(Native Method)
    at java.net.DatagramSocket.send(Unknown Source)
    at gov.nist.javax.sip.stack.UDPMessageChannel.sendMessage(UDPMessageChannel.java:743)
    at gov.nist.javax.sip.stack.MessageChannel.sendMessage(MessageChannel.java:242)
    at gov.nist.javax.sip.SipProviderImpl.sendRequest(SipProviderImpl.java:712)
    ... 38 more

关于我做错的任何想法?

1 个答案:

答案 0 :(得分:0)

为了记录,我已经解决了这个问题。 不久之前,我不记得到底出了什么问题,但显然我正在使用错误的.jar文件进行NIST实现。