0
我試圖使用NIST的JAIN SIP API實現發送REGISTER 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 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");
數據成員端口的值爲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
在我做錯了任何想法?
您確定沒有其他應用程序正在使用端口5060?你可以嘗試綁定到不同的端口,如5080,看看註冊是否有效。 – sipwiz 2011-04-06 22:45:05