Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Sip Registration help

  • 09-02-2010 11:14am
    #1
    Registered Users, Registered Users 2 Posts: 18,272 ✭✭✭✭


    Hi all,

    I'm currently using Jain Sip on Android and I'm trying to get a SIP registration working.

    I can put the registration SIP message together ok but after sending the message it seems to just get sent back to my application and my applications processRequest() method is run.


    Here is the code I'm using :

    public void init(TextView tv) throws Exception {
    		SipFactory sipFactory = null;
    		sipStack = null;
    		sipFactory = SipFactory.getInstance();
    		sipFactory.setPathName("gov.nist");
    		Properties properties = new Properties();
    		properties.setProperty("javax.sip.OUTBOUND_PROXY", getLocalIpAddress()+":8002" + "/"
    				+ ListeningPoint.UDP);
    		properties.setProperty("javax.sip.STACK_NAME", "Sip Test");
    		// Create SipStack object
    		sipStack = sipFactory.createSipStack(properties);
    		tv.setText("sipStack = " + sipStack);
    		headerFactory = sipFactory.createHeaderFactory();
    		addressFactory = sipFactory.createAddressFactory();
    		messageFactory = sipFactory.createMessageFactory();
    		lp = sipStack.createListeningPoint(getLocalIpAddress(),
    				8002, ListeningPoint.UDP);
    		
    		
    		sipProvider = sipStack.createSipProvider(lp);
    		sipOnOffFlag = true;
    		tv.append("\n jain sip stack started on " + getLocalIpAddress() + ":" + myPort + "/" + ListeningPoint.UDP);
    		sipProvider.addSipListener(this);	
    		
    		
    		String fromName = "019078020";
    		String fromSipAddress = "216.234.148.28";
    		String fromDisplayName = "Donal";
    
    		String toSipAddress = "216.234.148.28";
    		String toUser = "16784732970";
    		String toDisplayName = "Server";
    
    		// create >From Header
    		SipURI fromAddress = addressFactory.createSipURI(fromName,
    				getLocalIpAddress());
    
    		Address fromNameAddress = addressFactory.createAddress(fromAddress);
    		fromNameAddress.setDisplayName(fromDisplayName);
    		FromHeader fromHeader = headerFactory.createFromHeader(
    				fromNameAddress, null);
    
    		// create To Header
    		SipURI toAddress = addressFactory
    				.createSipURI(toUser, toSipAddress);
    		Address toNameAddress = addressFactory.createAddress(toAddress);
    		toNameAddress.setDisplayName(toDisplayName);
    		ToHeader toHeader = headerFactory.createToHeader(toNameAddress,
    				null);
    
    		// create Request URI
    		SipURI requestURI = addressFactory.createSipURI(toUser,
    				"216.234.148.28");
    
    		// Create ViaHeaders
    
    		List<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
    		String ipAddress = lp.getIPAddress();
    		ViaHeader viaHeader = headerFactory.createViaHeader(ipAddress,
    				lp.getPort(),
    				lp.getTransport(), null);
    
    		// add via headers
    		viaHeaders.add(viaHeader);
    
    		// Create ContentTypeHeader
    		ContentTypeHeader contentTypeHeader = headerFactory
    				.createContentTypeHeader("application", "sdp");
    
    		// Create a new CallId header
    		CallIdHeader callIdHeader = sipProvider.getNewCallId();
    
    		// Create a new Cseq header
    		CSeqHeader cSeqHeader = headerFactory.createCSeqHeader(1L,
    				Request.REGISTER);
    
    		// Create a new MaxForwardsHeader
    		MaxForwardsHeader maxForwards = headerFactory
    				.createMaxForwardsHeader(70);
    
    		// Create the request.
    		Request request = messageFactory.createRequest(requestURI,
    				Request.REGISTER, callIdHeader, cSeqHeader, fromHeader,
    				toHeader, viaHeaders, maxForwards);
    		// Create contact headers
    
    		SipURI contactUrl = addressFactory.createSipURI(fromName, getLocalIpAddress());
    		contactUrl.setPort(8002);
    		contactUrl.setLrParam();
    
    		// Create the contact name address.
    		SipURI contactURI = addressFactory.createSipURI(fromName, getLocalIpAddress());
    		contactURI.setPort(sipProvider.getListeningPoint(lp.getTransport())
    				.getPort());
    
    		Address contactAddress = addressFactory.createAddress(contactURI);
    
    		// Add the contact address.
    		contactAddress.setDisplayName(fromName);
    
    		contactHeader = headerFactory.createContactHeader(contactAddress);
    		request.addHeader(contactHeader);
    
    		// You can add extension headers of your own making
    		// to the outgoing SIP request.
    		// Add the extension header.
    		Header extensionHeader = headerFactory.createHeader("Expires",
    			"0");
    		request.addHeader(extensionHeader);
    
    
    		Log.d("SIP", "" + request.toString());
    		// Create the client transaction.
    		registerTid = sipProvider.getNewClientTransaction(request);
    
    		// send the request out.
    		registerTid.sendRequest();
    
    		dialog = registerTid.getDialog();
    	}
    

    So the message gets built ok but when sendRequest() is run it doesn't appear to get sent to the server but rather back to my application and the applications processRequest method is run.

    Should I be doing something extra with inviteTid or the dialog?

    Do I need to create a socket or something to sent the request out?


Comments

  • Registered Users, Registered Users 2 Posts: 7,518 ✭✭✭matrim


    I've never used JAIN SIP so this could be wrong but the problem may be
    properties.setProperty("javax.sip.OUTBOUND_PROXY", getLocalIpAddress()+":8002" + "/"
    + ListeningPoint.UDP);

    In SIP terms the outbound proxy normally refers to the server you are sending to so should probably be the external server's address and port instead of your own.


  • Registered Users, Registered Users 2 Posts: 18,272 ✭✭✭✭Atomic Pineapple


    matrim wrote: »
    I've never used JAIN SIP so this could be wrong but the problem may be



    In SIP terms the outbound proxy normally refers to the server you are sending to so should probably be the external server's address and port instead of your own.

    Thanks Matrim, I had just come back here to say that line was the problem :D

    Removing it completely has fixed it


  • Registered Users, Registered Users 2 Posts: 18,272 ✭✭✭✭Atomic Pineapple


    argh,

    have a new problem.

    I can register fine but when I go to re-register the new call id method throws a null pointer exception
    // Create a new CallId header
    		CallIdHeader callIdHeader = sipProvider.getNewCallId();
    

    Error:

    02-11 09:40:59.877: WARN/System.err(612): java.lang.NullPointerException
    02-11 09:40:59.877: WARN/System.err(612): at gov.nist.javax.sip.SipProviderImpl.getNewCallId(SipProviderImpl.java:230)

    Anyone come know why it would be null?


    EDIT:

    I figured out that the CallId should be the same with a registration with the server and not a new one each time so that fixed that.

    But Now I'm getting a nullpointer here:
    // Create the contact name address.
    		SipURI contactURI = addressFactory.createSipURI(fromName, "sip.network.com");
    		contactURI.setPort(sipProvider.getListeningPoint(lp.getTransport()).getPort());
    

    Error:

    02-11 11:04:08.727: WARN/System.err(1178): java.lang.NullPointerException


    Anyone any ideas?

    EDIT:

    Fixed that one too.

    I now have a null pointer exception from this line:
    inviteTid = sipProvider.getNewClientTransaction(request);
    

    And really cant figure this one out :(


Advertisement