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

发布于 2024-10-30 05:04:41 字数 5403 浏览 5 评论 0原文

我正在尝试使用 JAIN SIP API 的 NIST 实现发送 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:[email protected]","sip:127.0.0.1:5061");

The value of the data member port is 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

对我做错了什么有什么想法吗?

I'm trying to send a REGISTER SIP request using NIST's implementation of the JAIN SIP API.

First I give the declarations of the data members of my SipController class:

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;

And here is the code that sends the request:

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

I call this method using the statement

sipController.register("sip:[email protected]","sip:127.0.0.1:5061");

The value of the data member port is 5060.

What I'm trying to do is to send a request to another application running on my computer, which is listening on port 5061. This application is another instance of the same program that I'm sending the request from.

When I call the sendRequest() method of the SipProvider class, I get a javax.sip.SipException exception with message "IO Exception occured while Sending Request". This exception contains a java.net.BindException as its cause with message "Cannot assign requested address: Datagram send failed".

Here is the stack trace:

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

Any ideas on what I'm doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哥,最终变帅啦 2024-11-06 05:04:41

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

For the record, I've solved this problem.
It was a while ago so I don't remember exactly what was wrong but apparently I was using a wrong .jar file for the NIST implementation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文