Wednesday, October 22, 2008

Jain Sip is working on top of android

I had a bit of free time yesterday night and I noticed the first google android powered phone hit the market in USA so I said to myself, what if I tried to port jain sip stack to android...
Not so much work should be needed since android supports a lot of the JDK 1.5 packages natively. So I tried and believe it or not, no work was actually required to make the jain sip stack work on android, it just runs :-)
Again kudos to Ranga for such a great stack :-) and to Google for having a nice OS where you can really reuse most of your Java applications (pending a rewrite of the UI)

So here is my proof of concept :
I ported the well known Shootist and Shootme examples from the sip stack to android and uploaded a zip here that you can play with.

The zip contains shootist and shootme standard examples and shootist and shootme android examples. Unzip in a location that we will call

So first you need to have the android SDK installed and have the android tools on your path (see the Android installation instructions for that)

Then you can start the android emulator with the following command:
$ emulator

from , do the following :
$ cd shootme-android/bin/

and then
$ adb install shootme-android.apk 

this install the shootme android example application into the emulator
go back to and do the following :
$ cd shootist-android/bin/

and then
$ adb install shootist-android.apk 

this install the shootist android example application into the emulator

You can see the applications installed in the emulator by clicking on the gray arrow at the bottom of the android phone screen :

Ok so much for the installation of the applications into android. Now let's get real and have some fun. Let's try the shootme android application first.

on the emulator, go to the menu and select the application called shootme.
It says that the jain sip stack has started on (localhost's emulator ip address of android)

Since the emulator has its own ip address system we need to setup a UDP redirection from our host's localhost:5070 to the emulated system's localhost:5070 so that teh shootme android application can be pinged from our shootist standard application with the following command

$ adb emu redir add udp:5070:5070

let's start the standard shootist example so that it calls shootme and that a SIP call flow (INVITE-OK-ACK and then BYE-OK) is done between them.
go back to and do the following :
$ cd shootist/dist

and then
$ java -jar shootist.jar

you should now see the messages being exchanged between the shootme android application and the shootist standard application.

if the emulator sip messages are not enough, more log is available through the command
$ adb logcat

now kill the shootist app with Ctrl+C and close the emulator

You can also do the reversed example and start first the shootme:

Since the emulator has its own ip address system we need to setup a UDP redirection from our host's localhost:5060 to the emulated system's localhost:5060 so that the shootist example application can be pinged back from our shootme standard application with the following command

$ adb emu redir add udp:5060:5060

let's start the standard shootme example so that it waits to be called by the shootist android applicationand that a SIP call flow (INVITE-OK-ACK and then BYE-OK) is done between them.
go back to and do the following :
$ cd shootme/dist

and then
$ java -jar shootme.jar

on the emulator, go to the menu and select the application called shootist.

You should now see the messages being exchanged between the shootme android application and the shootist standard application.

if the emulator sip messages are not enough, more log is available through the command
$ adb logcat

Please post comments if you have problems running the examples or if you want to give me some feedback...


  1. Hi,

    Thanks for the article. I tried the app but no messages are being trasferred from/to emulator and the console app. I can see the text that the shootme android app has connected to, but when I tried running the console, nothing seems to happen. I also tried telnetting to but still, can't connect. Am I missing something here? Thanks in advance

  2. I'm going to stop everything I was doing and try this right now ;-).
    Great stuff Jean !

  3. @Marc : AFAIK, you won't never be able to to telnet a SIP server even more so on UDP, but you can try this command instead netcat -u -v -z localhost 5070. Also you will not be able to ping since this is the ipaddress on the emulator (it will not be available from your OS). Make sure you used the following command after having started the eumlator and the shootme application :
    adb emu redir add udp:5070:5070. This allow the host OS to contact the Android emulator on port 5070.

    Hope this helps.

  4. dicussion started here on this too

    1. Hi,
      Thanks for the article.

      I was installing shootme/shootist app on Nexus 4(Android 4.2.2).

      When I run these application, its always getting crashed with following logs:

      05-28 11:15:43.730: E/AndroidRuntime(5048): FATAL EXCEPTION: main
      05-28 11:15:43.730: E/AndroidRuntime(5048): java.lang.NoSuchMethodError: javax.sip.SipFactory.setPathName
      05-28 11:15:43.730: E/AndroidRuntime(5048): at
      05-28 11:15:43.730: E/AndroidRuntime(5048): at
      05-28 11:15:43.730: E/AndroidRuntime(5048): at
      05-28 11:15:43.730: E/AndroidRuntime(5048): at
      05-28 11:15:43.730: E/AndroidRuntime(5048): at
      05-28 11:15:43.730: E/AndroidRuntime(5048): at
      05-28 11:15:43.730: E/AndroidRuntime(5048): at$600(
      05-28 11:15:43.730: E/AndroidRuntime(5048): at$H.handleMessage(
      05-28 11:15:43.730: E/AndroidRuntime(5048): at android.os.Handler.dispatchMessage(
      05-28 11:15:43.730: E/AndroidRuntime(5048): at android.os.Looper.loop(
      05-28 11:15:43.730: E/AndroidRuntime(5048): at
      05-28 11:15:43.730: E/AndroidRuntime(5048): at java.lang.reflect.Method.invokeNative(Native Method)
      05-28 11:15:43.730: E/AndroidRuntime(5048): at java.lang.reflect.Method.invoke(
      05-28 11:15:43.730: E/AndroidRuntime(5048): at$
      05-28 11:15:43.730: E/AndroidRuntime(5048): at
      05-28 11:15:43.730: E/AndroidRuntime(5048): at dalvik.system.NativeStart.main(Native Method)

      Actually I have to use JAIN SIP to send Register and Invite Request to SIP Server so that I can send command to SIP server to initiate GSM call.

      Please reply!!

  5. I manage to run the shootist/shootme example by following the instructions and it's working properly. I'm running the android emulator under MacOSX. Marc be sure to redirect the UDP socket using the command described in the post and start the shootist program inside the console.

    The great thing about this example is that uses plain JSIP stack not the j2me version. This allows developers to use the same API to develop server side application and device applications.

  6. To understand the implications of what jain sip on top of android means. See this blog post by Francesco Moggia

  7. Thanks a million. I cant express how happy I am :).

  8. It is great to see some active developement on this. I saw over on the google groupe page that there is intrest in RTP and getting this working for streaming voice. I have to say that would be wonderful. One step closer to a working VoIP client. Thanks for all your work.

  9. Hi, I tried to run but do not see messages being trasferred from/to emulator. I did do UDP redirect thingy. Any suggestions will be appriciated. Thx

  10. Thanks for the reply Jean. I will try it once again.

  11. I am new to Log4J and I noticed JAIN SIP uses it for logging. How do I make Log4J redirect the log statement to Android's console? Thanks!

  12. I tried ur way but,
    getting following out:

    E:\Application\Android\jain-sip-android on ps4025\shootist\dist>java -jar shooti
    createSipStack gov.nist.javax.sip.SipStackImpl@1404536
    Transaction Time out
    Transaction terminated event recieved

    what is the problem?

  13. Hi All,

    This is very nice article i have read.
    I am unable to extract the uploaded the Files.
    Can any one tell me where i can get the uploaded files.


  14. Dear Jeane,

    I am a student and I have been trying to implement an SIP IM client on android using the JAIN SIP stack implementation. There is an error that I get which i cannot understand how to debug and was wondering if you can throw some light on it:

    There is a frontend GUI which calls the SIPclient through Intents but when executing the code this fails when we create the `Listeningpoint` , this application runs properly when it is invoked directly without an intent.

    Could you please tell me if there are any precaurtions that have to be taken when creating the Listeningpoint ?

  15. @J : I think just logging to the console (Standard output) will allow to see the messages in adb logcat

  16. @Su : I'm sorry my knowledge of Android is still somewhat limited and I never used Intents, so I guess you're on your own. sorry about that

  17. Hi Folks,

    Got it working finally. I wasn't able to make it work using this command:

    adb emu redir add udp:5070:5070

    but using these steps instead: First telnet to your emulator. 5554 is the port on first emulator instance.

    telnet localhost 5554

    then inside telnet session, execute the following command:

    redir add udp:5070:5070

    then it will reply OK. then try running your java program again. You should now be seeing messages from/to emulator and java program.

    I'm using android SDK 1.0 by the way.

  18. Hi Jean,
    Thanks for the great work...I could run your zipped code and they worked just fine. However, when I tried running the code by creating a project of my own in Eclipse, I am getting some errors from the dalvik compiler...probably the same Intent related error as Su had mentioned earlier in this comments section..I am using the same set of jars you have used for your shootist-android. The only possible difference could be in the android version that we are using - I am using 1.0_r2. Could you please let me know which version you used to compile your code? I would greatly appreciate any other suggestions/insight/comments regarding the problem. the I am copying below the error that I am getting for your reference:

    I/ActivityManager( 53): Starting activity: Intent { flags=0x10000000 comp={com.client/com.client.CallAndroid} }
    D/AndroidRuntime( 181): Shutting down VM
    D/dalvikvm( 181): DestroyJavaVM waiting for non-daemon threads to exit
    I/dalvikvm( 181): DestroyJavaVM shutting VM down
    D/dalvikvm( 181): HeapWorker thread shutting down
    D/dalvikvm( 181): HeapWorker thread has shut down
    D/jdwp ( 181): JDWP shutting down net...
    I/ActivityManager( 53): Start proc com.client for activity com.client/.CallAndroid: pid=188 uid=10024 gids={}
    D/dalvikvm( 181): VM cleaning up
    D/dalvikvm( 181): LinearAlloc 0x0 used 539316 of 4194304 (12%)
    I/jdwp ( 121): received file descriptor 26 from ADB
    D/SSLSocketFactory( 188): Using factory org.apache.harmony.xnet.provider.jsse.OpenSSLSocketFactoryImpl@4011c688
    E/OSNetworkSystem( 188): unknown socket error -1
    W/System.err( 188): log4j:WARN No appenders could be found for logger (shootist).
    W/System.err( 188): log4j:WARN Please initialize the log4j system properly.
    W/System.err( 188): javax.sip.InvalidArgumentException: unknown error
    W/System.err( 188): at gov.nist.javax.sip.SipStackImpl.createListeningPoint(
    W/System.err( 188): at com.client.CallAndroid.init(
    W/System.err( 188): at com.client.CallAndroid.onCreate(

    W/System.err( 188): at
    W/System.err( 188): at
    W/System.err( 188): at
    W/System.err( 188): at$1800(
    W/System.err( 188): at$H.handleMessage(
    W/System.err( 188): at android.os.Handler.dispatchMessage(
    W/System.err( 188): at android.os.Looper.loop(
    W/System.err( 188): at
    W/System.err( 188): at java.lang.reflect.Method.invokeNative(Native Method)
    W/System.err( 188): at java.lang.reflect.Method.invoke(
    W/System.err( 188): at$
    W/System.err( 188): at
    W/System.err( 188): at dalvik.system.NativeStart.main(Native Method)
    W/System.err( 188): Caused by: unknown error
    W/System.err( 188): at gov.nist.javax.sip.stack.UDPMessageProcessor.&lt init &gt (
    W/System.err( 188): at gov.nist.javax.sip.stack.SIPTransactionStack.createMessageProcessor(
    W/System.err( 188): at gov.nist.javax.sip.SipStackImpl.createListeningPoint(
    W/System.err( 188): ... 15 more

  19. I use 1.0_r1 indeed. I will give it a try on rc2 and get back to you. (this is on my free time so it might take a few days, sorry)

  20. Thanks a lot Jean..I will look forward to hear about your experience with the later distribution. Meanwhile I will give a shot with 1.0_r1. Thanks again.

  21. i'm write a jain-sip registration code but my program terminate what i do???????

  22. how to port j2me sip stack(which is already built) on to android

  23. Hi Jean, do you have any idea if anyone has done the IMS registration portion using the JAIN SIP stack similar to yours?

  24. @Joseph Teo : no but you can look at the source code. This is an IMS client based on SIP Communicator (which is using JAIN SIP) and try to extract the registration part and port it to Android.

  25. Is there a way to capture the packets like using wireshark?

  26. Is there a way to capture the packets (like using wireshark)

  27. @jpena930 : yes you should be able to do so to at least see the packets coming from the emulator or going to the emulator

  28. Hi, I can't get it done right. I'm using android-sdk-windows-1.1_r1.
    Android shootist sends SIP message, classic java app shootme process this sip message, send response..but this response never arrives to android shootist...

    I tried adb emu redir add udp:5070:5070 and every possible port combinations :P and also the telnet thing like Marc Lester said but...nothing :-/

    Please do you have any idea why?

  29. Hi Jean
    I have a j2me sip stack which has been written using jsr 180.Do u have any idea of porting it to android if so wat changes i need to make.please throw some light on this issue

  30. "...and to Google for having a nice OS where you can really reuse most of your Java applications (pending a rewrite of the UI)..."


  31. An update to this wonderful post.

    I tried to compile the jain sip stack source on the android platform (instead of importing the jars in the project).

    This converted the class files into dex format and i observed a 20% reduction in the static footprint of the dummy application.

    Also, the runtime heap allocation for the dummy app reduced by 20-25%.

    A bit of profiling for the Shootist app also revealed that the CPU utilization was pretty nice and around 1%.

  32. @Aayush : Thanks :-) That's definitely interesting. Could you provide the steps for compiling the jain sip stack source on the android platform ? I will then update this post with your findings or if you have a blog post about that I can link to you.
    Would also be interested in knowing what you use to profile on android ?

  33. There are 2 ways to do the compilation: The easy way and the hard way !

    Easiest way is to include the jain sip source packages in the android project and create the apk.

    The classes.dex inside the apk will contain the dex bytecode for the stack+application. Doing this itself helped reduce the footprint (static on the disk and also at the heap).

    The harder way is to use the dx command line utility like this:

    Navigate to the installation of the SDK on your machine and then go to the tools folder under platforms (there is another tools beware!):

    Now give this command:

    dx --dex --output=classes.dex jain-sip-ri-1.2.122.jar jain-sip-api-1.2.jar

    I had copied the jsip jars in the tools folder itself before this command.

    For memory profiling and allocation tracking etc, we can do the following:

    1. go to ANDROID_HOME/tools (the other tools folder i was talking about).

    2. issue emulator -adb adb-name

    3. issue ddms command. Now the dalvik debug monitor will appear. Select the PID of your application and then go to the allocation tracker tab. Click on Start allocation to see the object allocations.

    4. On the DDMS, goto sysinfo tab and click on "Update from device" to see the CPU utilization.

    5. For heap usage details, select your process ID from the list and then click on the little green cylindrical button on the toolbar. Now goto he VM heap tab and click on Cause GC to see the information.

    6. For tracing method-by-method calls..there is a separate procedure. Its a little more complicated though..but very useful.

    Pretty kool tools !! I can mail u the screen shots if u like.


  34. I am a newbie...Needs to develop an IMS registration code using JAIN SIP..Can you please suggest"how to start the develoment procedure or from where i can get some thorough assistence...

  35. Hello all real nice job and thanks for sharing. Also well done to jain-sip creators and google for the quality software. I have found this stack for RTP:
    and also I think sipdroid has rtp support so it can be ported from there.
    Actually I decided to post for new developers looking for this and I am wondering why the port mentioned above have stopped? thanks maxsap

  36. @maximos Lack of time unfortunately...

  37. Hi Jean,

    I have the shootme-android running on my device but is there anyway to see the messages being passed to an actual device?

  38. Hi jean, just thinking if you have a snippet on how to make a call using JAIN SIP?

  39. @Michael, the zip mentionned in the article contains which does create a SIP Call (sends INVITE and reply to 200 OK with ACK). Did u check it out or are you looking for something else ?

  40. Hi jean, when i say call it means, trying to call my cellularphone's number i think it was always a sip URI. This i don't understand where to start thanks...i need to make a simple test call using JAIN SIP to android and then call my cell number - a ring in my cell would be a success hehehe

  41. one more thing i am new to SIP technology so maybe i can ask you questions regarding these... heheh thanks.. do you have a IM or in skype?

  42. @Michael you would need to use a voip online provider such as or SIP gateway to bridge to the legacy telephony network. I'll try to do another blog post about next week.
    Google Talk id : jean.deruelle

  43. Hi Jean,

    I have taken down your Shootist android example and I have tried to get a SIP registration working by changing the code around a bit.

    I am able to create the correct Sip Message and content to send it.

    However the request always seems to get sent back to the device and the processRequest method is run.

    I expect this shouldn't be happening and I was wondering is there something in the code that stops me sending the request to a server over wifi from a device?

  44. Nevermind Jean, I got it working :-)

  45. Hi Jean,

    I have used the Shootist example to send a register message.

    Get the 401 UnAuth back with the challenge.

    Generate the response and send the register again.

    And get the 200 OK response back.

    So thats all ok, but when I try to re register after a set time I get null pointers no matter what I try.

    Would you have any advice for me on how to re register properly?

    I've added you on Google Talk if you dont mind?

    1. Hi Donal,

      Can you please tell me steps how did you sent register message.

      I have to send register message and after receiving acknowledgement, I have to send Invite request.

      So I can send request to SIP Gateway to initiate GSM call.

  46. This comment has been removed by the author.

  47. Is it possible to get/store the received Message Body (plain/text) in a String?

  48. @George just do String content = new String(message.getRawContent()); (you may want to pass the charset in param as well to the String constructor)

  49. @jean thanks! that worked.
    I am now trying to send a 200 OK message every time I get a requestEvent. I guess I should mess around with processRequest() for this, right?

  50. yes, I would suggest you check out jain sip from CVS and look at the code in src.examples.simplecallsetup

  51. Hi Jean,
    In this your shootist/shootme example I tried to put MOBICENTS Sip servlet as a proxy. I used an example "LocationServices" taken from mobicents documentation with small changes in code. With standard shootist/shootme examples this works perfectly, but when I take the shootist android example, shootist fails to send the ACK message, and he receiving in the loop OK messages from shootme.

    Do you know where could be a problem?

  52. This comment has been removed by a blog administrator.

  53. Hi, Jean D.

    Thanks for the work done on Android with sip jain libraries and posting them for every one.

    I'm quiet new at Sip and also Android...i'm trying to figure out how I could establish a call (Voip) between an Android device and the emulator (P2P) in a private Lan...

    can you suggest a way I should follow to achieve this purpose?

    (I'm thinking of installing the shootist code on the device and the shootme on the emulator, changing addresses)

  54. Very Very cool, interesting, and very informative, really nice, keep it up.

    android mobile

  55. when i tried to run shootist.jar(in windows), its giving Address already in use. Cannot bind. Please suggest me to make it run.

  56. This comment has been removed by a blog administrator.

  57. Nice example, it worked for me.
    I am looking for an example for making a call [instead of MESSAGE] using JainSIP to SIP Server [owned by VoIP provider] to place a telephone call.

    I used JainSIP to Create a SIP Client and connect/communicate with a SIP Sever [owned by VoIP provider] and send Requests for INVITE, REGISTER etc and it works fine.
    But, I want to advise SIP Server to place a call to real phone number "".

    SIP Server allows following Request types [Allow: ACK,BYE,CANCEL,INVITE,
    REGISTER,OPTIONS,INFO,MESSAGE], which one should I use to tell SIP server to place a call and what is the format, should I create anew Header etc.


    1. Hi Sreedhar,

      My requirement is same as you have done.

      I took reference from but I am unable to connect/communicate to SIP server.

      I would be really great help if you can share some piece of code.
      Please help me in this.

  58. This looks actually perfect. All these tinny capacity are fabricated with lot of accomplishments knowledge. I like it a lot. This was a advantageous column and I anticipate it is rather accessible to see from the added comments as able-bodied that this column is able-bodied accounting and useful

  59. Where can one download Jain SIP library source code that can be compiled for Android?

  60. Hi Jean, I'm a Java/Android newbie and I need to develop an android application which discusses in SIP with an existing server application.

    Could you help on the following two issues:

    I use Eclipse as development environement.
    I've imported jain-sip-api-1.2.jar as a library into my android project but I faced Dalvik conversion problem:
    trouble processing "javax/sip/ClientTransaction.class":...Conversion to Dalvik format failed with error 1
    I've tried to make it works with Android 3.2 and Android 4.0. Both resulted in the same issue.

    I've followed step by step procedure you've written in this post.
    When I launch Shootme application on device emulator I see a message "Unfortunatly, shootme has stopped."
    In Eclipse, LogCat window shows me the following error:
    java.lang.NoSuchMethodError: javax.sip.SipFactory.setPathName
    at android.os.Handler.dispatchMessage(
    at android.os.Looper.loop(
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(
    at dalvik.system.NativeStart.main(Native Method)
    Force finishing activity

    I suppose I missed a major step or component.
    Your help would be welcomed. Thanks.

  61. Can you post your question to ?
    I never tried on Android 3.2 or 4 so not sure I can be of any help as my time to play with it is a bit scarce now.
    Be aware that Android devices from 2.3+ already ship the JAIN-SIP Stack and provide an abstraction layer on top of
    Not sure if that could help you out.


    1. I need to deal with particular SIP headers. Provided abstraction layer doesn't seem to meet my needs.
      Thanks for answer and advice.

  62. the emulator has its own IP address system we need to setup a UDP redirection from our host's should now see the messages being exchanged between the short time android application

  63. Hi jean
    I have taken down your Shootist android example and I done with connecting two emulators and able to send INVITE and INVITE-ACK

    Now i am trying send voice stream through Rtp, here i am not succeed ,Please you guide me how send and receive media using Rtp


  64. Hey I am running a business in uk and I am looking some SIP Providers that reduce cost and also improve communication level because By using a business SIP trunk to combine voice and data, you can drop your analogue ISDN and save more than 60% on connectivity charges. Please suggest me something like this SIP Providers