Thursday, September 24, 2009

MSMQ - Connecting Remote MSMQ

Connecting to remote MSMQ can be an easy task, yet, it can be a difficult one.

First, if you want to connect to a remote MSMQ, you have to define the queue name with FormatName

For machine name, use FormatName:Direct=OS:mymachine\private$\remoteQueue

For IP, use FormatName:Direct=TCP:\private$\remoteQueue
The above is for Private Queue. If you want to connect to a Public queue, just remove private$ from the above string. Also, please note that you cannot use IP address on OS and vice versa.

Now, you are ready to program. All you need is 3 lines for send and 5 lines for receive

Note: the example is for private queue. For public queue, remove private$ from queuePath

C# code for Send

String queuePath = "FormatName:Direct=TCP:\\private$\\remoteQueue";

MessageQueue mq = new MessageQueue(queuePath);


C# code for Receive

String queuePath = "FormatName:Direct=TCP:\\private$\\remoteQueue";

MessageQueue mq = new MessageQueue(queuePath);

System.Messaging.Message msg = mq.Receive();

msg.Formatter = new XmlMessageFormatter(new string[] { "System.String" });

Console.Write("received message: " + msg.Body);


1. For receive, the above code perform receive synchronously. Thus, it will suspend the thread and only return when a queue message is received

2. Programming with MSMQ become tough and waste a lot of time if you did not read the API correctly. For example, MessageQueue.Exist(). This method only work for local queue. It will fail on all remote/Direct FormatName where machine in Workgroup mode. Please read carefully.

Wednesday, September 23, 2009

MSMQ - Installing MSMQ with XP Pro

Installing MSMQ in XP Pro is not really difficult, do the following

1. Control Panel -> Add Or Remove Program -> Add Or Remove Windows Components -> Message Queuing. Just check the checkbox on Message Queuing.
2. Just let it install. If install successfully, you can go Control Panel -> Computer Management -> Services and Applications -> Message Queuing to configure message queue.

Some unsaid prerequisite

1. Internet Information Services (IIS) must be installed
2. NT LM Security Support Provider Service must be enabled. If not, you will be prompted with "The Dependency service or group failed to start"

Wednesday, September 16, 2009

J2ME - Setting Eclipse to use CLDC 1.1 Part 2

The previous post will work for creating new project. For exisitng project that meet with Float compile issue, on top of the previous post setting, please do the following.

1. Go to the Application Descriptor at Package Viewer and open it.
2. Change Mircroedition configuration and Microedition profile to 1.1 and 2.1 respectiviely.
3. At the runtime section where you can specify the device and environment, add a new device. Please choose the device that you had set up for CLDC 1.1 and MIDP 2.1 based on the previous post
4. Remove the old device and use the newly added device.
5. Save the Application Descriptor and rebuild the project.

Tuesday, September 15, 2009

J2ME - Setting Eclipse to use CLDC 1.1

If you had followed my last post to setup eclipse to use J2ME SDK 3.0, you will slowly find out that you could not use Float. This is because CLDC 1.0 does not support floating precision.

If you look closely, you will find that Java Wireless Toolkit 2.5.2 support CLDC 1.1 and MIDP 2.1. Then how could J2ME SDK 3.0, a better version of JWT 2.5.2, does not support that.

The problem is when you configure Device Management at Eclipse, it includes both CLDC 1.0 and CLDC 1.1 jar. If this happen, Eclipse will use the lower version. To fix this, do the following

1. Go to Window -> Preferences Menu
2. Under J2ME -> Device Management.
3. You will find the configuration and profile is 1.0 and 2.0 for most device.
4. Select a device, ie DefaultCldcPhone2, click on Edit button.
5. Click on libraries tab, you should see a list of libraries that this device is referred to.
6. Now, find and remove cldc_1.0.jar and midp_2.0.jar entry. Also, make sure cldc_1.1.jar and midp_2.1.jar exists.
7. Save all changes and you will eventually back to the Device Management page.
8. Now, you should see the configuration and profile is 1.1 and 2.1 for the modified device. If you see that, you are ready to use float.

Monday, September 14, 2009

J2ME - Setting up Eclipse For JavaME

I am not going to give a tutorial on how to setup Eclipse MTJ for JavaME. I am going to give all the links in sequence for you to set up Eclipse with MTJ.

Side note: JavaME 3.0 comes with an IDE, it is an nice IDE except debugging. It require NetBean graphic debugger attach to it in order to perfrom debugging. Thus, Eclipse is better in debugging point of view.

Setting up Eclipse for JavaME

1. Download JavaME latest version at

2. Install JavaME with the download executable. Note: Remember the installation location. It is require to set up Eclipse

3. Download Eclipse MTJ at

4. Unzip the downloaded MTJ. It contains an eclipse folder. Copy the contents inside MTJ's eclipse folder to your eclipse installation folder. I did not use software upgrade feature in Eclipse because it failed on me

5. Download Proguard at It helps to bfuscate your application build.

6. Unzip the download proguard to any location. Remember this location as it is required for Eclipse set up

8. If you follow the Eclipse help link to set up Eclipse for JavaME, you are now ready to use Eclipse to do JavaME programming.

Monday, September 7, 2009

Linux - Encrypted Partition

Creating Encrypted Partition in Unix is not that hard. I will show the sequence of commands with dd, cryptsetup, losetup and mount to create a encrypted partition. Make sure you have the above commands installed. (ie, you can use apt-get install cryptsetup to install cryptsetup)

Creating an Encrypted Partition

1. Creating a file with 5MB. Note: The encrypted.img is self-defined

 dd if=/dev/urandom of=encrypted.img bs=1M count=5

2. Tell Linux to treat it as a disk device. Note: you can use loop0 to loop9.
 sudo losetup /dev/loop0 encrypted.img 

3. Create AES encrypted partition with 256 key length

 sudo cryptsetup luksFormat -c aes -s 256 /dev/loop0

4. Tell Linux to treat the encrypted partition as disk device. Note: encryptedVolume is self-defined

 sudo cryptsetup luksOpen /dev/loop0 encryptedVolume 

5. For the encrypted volume

 sudo mkfs -t vfat /dev/mapper/encryptedVolume 

6. Close encrypted volume

 sudo cryptosetup luksClose encryptedVolume 

7. Detach the device

 sudo losetup -d /dev/loop0 

Using the Encrypted File

1. Tell Linux to treat file as device

 sudo losetup /dev/loop0 encrypted.img 

2. Tell Linux to treat the ecnrypted partition as disk device

 sudo cryptsetup luksOpen /dev/loop0 encryptedVolume

3. Mount the disk to /mnt. You can access the files at /mnt after the command execution

 sudo mount /dev/mapper/myvolume /mnt

Cleanup After Usage

1. Unmount the volume

 sudo umount /dev/mapper/encryptedVolume

2. Close the encrypted volume

 sudo cryptsetup luksClose encryptedVolume

3. Detach the loop device

 sudo losetup -d /dev/loop0

Linux - dd Command

dd is an abbreviation for "dataset definition". Its primary purpose is the low-level copying and conversion of raw data.

dd can also be used to copy regions of raw device files or to read fixed amounts of data from special files like /dev/zero or /dev/urandom.

/dev/zero - a special file that provides as many null characters

/dev/urandom - a special file that serves as a true random number generator or as a pseudorandom number generator.

Example use of dd command

1. Create an ISO Disk Image from a CD-ROM:

dd if=/dev/cdrom of=/home/myhome/my.iso bs=2048 conv=sync,notrunc

2. Destroy data on a partition with null data

#Do not execute this code on any computer unless you want to destroy all data on a partition! 

dd if=/dev/zero of=/dev/

3. duplicate one hard disk partition to another hard disk

dd if=/dev/sda2 of=/dev/sdb2 bs=4096 conv=notrunc,noerror

Ubuntu - Install Java 6

To install Java 6 in Ubuntu, you could install by downloading the install package from Java website.

Another easier way is to use apt-get, type the following

sudo apt-get install sun-java6-jdk

This will install latest Java 6 JDK

Wednesday, September 2, 2009

Ubuntu - Default VI is really bad

Recently, I had been using Ubuntu's default VI. I almost vomitted blood while using it. I had no idea how to delete, how to navigate around. Normal VI command is in a mess and arrow button create clueless characters.

In the end, I reinstalled the VI by using apt-get install vim-gnome command.

After the install, VI is back to normal again.

LDAP - Deleting an LDAP entry

To delete an ldif entry, one way is to put an changetype attribute and a value 'delete' in the ldif file For example dn: cn=so...