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

使用NIST JAIN SIP API发送SIP请求时出错,sip,jain-sip,Sip,Jain Sip,我正在尝试使用NIST的JAIN SIP API实现发送注册SIP请求 首先,我给出SipController类的数据成员声明: private int port; private long cseq = Math.abs(numberGenerator.nextInt()); private MessageFactory messageFactory; private AddressFactory addressFactory; private HeaderFactory headerFact

我正在尝试使用NIST的JAIN SIP API实现发送注册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);  
}
数据成员端口的值为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

你知道我做错了什么吗?

说实话,我已经解决了这个问题。
那是很久以前的事了,所以我不记得到底是什么地方出了问题,但显然我在NIST实现中使用了一个错误的.jar文件。

你确定没有其他应用程序使用端口5060吗?您可以尝试绑定到不同的端口,如5080,然后查看寄存器是否工作。
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