Reputation: 2170
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:user@domain.com","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?
Upvotes: 0
Views: 2160
Reputation: 2170
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.
Upvotes: 1