javaandroidjain-sip

JainSIP, simple user registration


I've got a simple code for user registration. Of course, it doesn't work, because I'm new at Jain SIP stack, and I don't understand many things. I tried to imitate the Android SIP API, but unsuccessfully.

import javax.sip.SipFactory;
import javax.sip.address.Address;
import javax.sip.address.AddressFactory;
import javax.sip.address.SipURI;

public class SimpleUser {

    SipURI sipURI;
    Address address;
    AddressFactory addressFactory;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new SimpleUser().init();
    }

    public void init() {
        try {
            addressFactory = SipFactory.getInstance().createAddressFactory();
            //sipURI = (SipURI) address.getURI();
            sipURI = addressFactory.createSipURI("user", "domain");
            sipURI.setUserPassword("pass");
            //SipURI uri = (SipURI) addressFactory.createURI("sip:user@host");
            sipURI.setTransportParam("UDP");
            sipURI.setPort(5060);
            address = addressFactory.createAddress("user", sipURI);
            Thread.sleep(10000);
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

}

Could someone direct me what I need to improve in order to properly connect to the SIP server.

PS. How can I check if the user has registered? I need something like a method isRegistered()

Best regards.


Solution

  • Sending requests is a lot more involved I am afraid. See this example, the sendRegister() method. This example uses websocket transport so you need to change to UDP. In fact you should probably go ahead and look into several examples to get the idea.