SMS message exchange between BlackBerry simulator instances: a very simple demo

If you’re writing a BlackBerry Java application that sends and/or receives SMS text messages, naturally you need to be able to test the application on the simulator.  And naturally the simulator doesn’t really send SMS messages, so you need to know how to get the simulator to exchange simulated SMS messages with another instance of the simulator.

This is very easy to do.  You can do it with the SmsDemo that comes in the BlackBerry JDE’s sample applications bundle — even though the SmsDemo’s JavaDoc seems to imply that you can’t.  If you look in the code of SmsDemo.java (usually found at C:\Program Files\Research In Motion\BlackBerry JDE <version>\samples\com\rim\samples\device\smsdemo), the JavaDoc says the following:

This program requires the associated server component found in the com.rim.samples.server.smsdemo package under the samples directory in your JDE installation.

That’s not precisely true.  It doesn’t require the server component — it can actually send demo messages from one instance of the simulator to another, as long as you set the sms-source-port of the one to be the sms-destination-port of the other, and vice-versa.  There are just a few quick steps and notes for launching the two instances:

The simulator executable is called “fledge.exe” and it is found in the simulator directory of the JDE installation (usually under C:\Program Files\Research In Motion).  You can run fledge from the command line or from a batch file with command line options specified with the usual Windows style (with a leading “/” instead of a “-” for you *nix developers).  Here’s an example of the command to launch the first one:

C:\BlackBerry\my-simu-directory-1>”C:\Program Files\Research In Motion\BlackBerry JDE 4.2.0\simulator\fledge.exe” /app=”C:\Program Files\Research In Motion\BlackBerry JDE 4.2.0\simulator\Jvm.dll” /sms-source-port=5000 /sms-destination-port=5001

Then launch the second instance (from a different directory) with the source and destination port numbers inverted.

Since the fledge executable requires you to specify the JVM DLL in the “/app” option, you might think it would be easier to just navigate to the simulator directory and launch it from there.  The problem is that the simulator stores a set of files in the directory you launch it from, and it won’t let you run two instances simultaneously from the same directory.  The trick is to either write a batch file to launch both or — my personal favorite — an Ant target, such as the following:

<project default=”sms-run”>

<property name=”jde.home”
value=”C:\Program Files\Research In Motion\BlackBerry JDE 4.2.0″
/>
<property name=”model” value=”8100″ />
<property name=”build.root” value=”C:\BlackBerry\smsbuild” />

<target name=”sms-run”>
<!– run two simulators that can communicate with one another via sms –>
<mkdir dir=”${build.root}\sms-simu-1″/>
<exec executable=”${jde.home}\simulator\fledge.exe”
dir=”${build.root}\sms-simu-1″
spawn=”true”>
<arg value=”/app=${jde.home}\simulator\Jvm.dll”/>
<arg value=”/handheld=${model}”/>
<arg value=”/app-param=DisableRegistration”/>
<arg value=”/app-param=JvmAlxConfigFile:${model}.xml”/>
<arg value=”/pin=0x2100000A”/>
<arg value=”/sms-source-port=5000″/>
<arg value=”/sms-destination-port=5001″/>
</exec>
<mkdir dir=”${build.root}\sms-simu-2″/>
<exec executable=”${jde.home}\simulator\fledge.exe”
dir=”${build.root}\sms-simu-2″
spawn=”true”>
<arg value=”/app=${jde.home}\simulator\Jvm.dll”/>
<arg value=”/handheld=${model}”/>
<arg value=”/app-param=DisableRegistration”/>
<arg value=”/app-param=JvmAlxConfigFile:${model}.xml”/>
<arg value=”/pin=0x2100000B”/>
<arg value=”/sms-source-port=5001″/>
<arg value=”/sms-destination-port=5000″/>
</exec>
</target>

</project>
To run this example, just create the ${build.root} directory (here it’s “C:\BlackBerry\smsbuild”), and change the JDE version number to whichever version you’re using.  If you’re not using BlackBerry JDE 4.2.0, then you’ll also have to change the model number to some model that has a corresponding xml file in your JDE’s simulator directory (or just delete the model-related arguments).

Also note that when you launch the second instance of the simulator, it will give you an error message because the first instance is using the port that the simulator normally uses to communicate with the debugger.  Just select “ignore”, as explained in the BlackBerry knowledge base here.  I tested a few of the other fledge options (which I found by running fledge /help from the command line), but none of them seemed to allow me to switch the port number for the debugger or to just eliminate the message from being displayed.

The last thing to note is that the SmsDemo application obviously has to be installed on the simulator you’re using.  If you open the “samples” project in the JDE and select “build all” or “build all and run” from the “build” menu, then the application will be installed on the simulator.  You only need to do it once, and the SmsDemo will be there (in the simulator’s Applications menu) when you run the simulator from the command line or the Ant script.

Both instances must be running the SmsDemo application in order for them to communicate with one another — sending a message from one won’t launch the application on the other.  The destination address you enter in the SmsDemo application doesn’t matter — it appears to be ignored.  The port information above directs the message to the other simulator, and the SMS address string (in the SmsDemo code) specifies an application port number so that the message is directed to the SmsDemo application on the other simulator (and not to the other simulator’s “messages” folder).

Advertisements

4 comments so far

  1. […] How do you simulate the SMS to test the application launch with the PushRegistry?  I explained that here. […]

  2. Jon on

    Hi Carol,

    I was able to launch the 2 simulators but I did not receive any incoming messages.

    I put the following script in batch files in seperate directories and flipped the ports.

    “C:\Program Files\Research In Motion\BlackBerry JDE 4.7.0\simulator\fledge.exe” /app=”C:\Program Files\Research In Motion\BlackBerry JDE 4.7.0\simulator\Jvm.dll” /sms-source-port=5001 /sms-destination-port=5000

    Am I doing something wrong?

  3. carolhamer on

    Hi Jon,

    Sorry to start with a stupid question, but did you install and launch the SMS Demo application on both simulators? The app has to be running on both simulators for it to work. Otherwise, I don’t see anything wrong with what you’ve typed…


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: