Develop your own MSN java client.

by : Ivan Shi

Now, use msnmlib 1.2(the website is in Korean), you can write programs as client to MSN servers.
You can write msn robots or your own MSN Messenger use Java.

Here I have a very short tutorial on how to use msnmlib 1.2, and my Java development IDE is Eclipse 3.0

Prepare:If you had already downloaded msnmlib 1.2 package?from the offical project website,? then unzip it to any folder on your HDD.Here I use d:java_devcommon?,you will get a jar file: msnm.jar.Otherwise, you have to download the latest version of msnmlib from the offical web site or the project page on sourceforge

First step, open your Eclipse IDE and use New Project wizard to create a new java project in your default workspace(ofcoz, you can use another workspace), and name your project(here I use jRCS,which means java Realtime Customer Servcie System)

Second, In Eclipse, Select menu Window--> Prefence, expand the Java node in the left treeview,
and then expand Build path node in Java node, and then select node User Libraries. We will add a new user library refer to the?path where you place your msnmlib jar file. Click new... to add a new user library MSN_LIB and click Add Jars... to make the user library variable refer to msnmlib jar file:d:java_devcommonmsnm.jar

Now, edit properties of project jRCS by select the context menu of jRCS node?in the Project Explorer.?Here we will edit the Java Build Path and add a new library for this project. Of coz, we will add the pre-defined User Library MSN_LIB?here.

Ok, finally, we have our development environment set up. It's time for coding!

Coding Step 1: Create?your own MsnAdapter class?for an adapter that can listen to the events fired?by MSN Messenger.?You should make you?adapter class extend from the?parent class rath.msnm.event.MsnAdapter. the MsnAdapter class has more the 10 methods for event listening. but you have not to implement all the?methods, and?by user Eclipse?New Class Wizard, it is not a?hard job to implement a lot?of?methods.?For short and easy, We only implement?method MsnAdapter.instantMessageReceived(SwitchboardSession ss, MsnFriend friend,??????????? MimeMessage mime).
Method instantMessageReceived is invoked?by the MsnMessenger?instance every time when?you receive a new message?(MimeMessage)?from MsnFriend.
Here is my code to reply to the?friend?"How are you doing":

public class MSNAdapter extends MsnAdapter {
MSNMessenger msn;

public MSNAdapter(MSNMessenger msn) {
this.msn = msn;

public void instantMessageReceived(SwitchboardSession ss,
MsnFriend friend, MimeMessage mime) {
+" send me some msg:"+mime.getMessage());
// create a new message
MimeMessage mm = new MimeMessage();

// remember to append the

trail to
// your message
mm.setMessage("How are you doing?

// set the message kind to MESSAGE -_-!!!
// you have to do this.

if (robot.msn.sendMessage(mm,ss))
// message sent successfully
System.out.println("send msg ok!");
// failed
System.out.println("send msg faild!");
}catch(Exception e){

Coding Step 2: Write a public?class?with the static
main method as your own msn client.

public class Client {

public static void main(String[] args) {
Email = "";
Password = "you_msn_account_password";
// create a new MSNMessenger instance msn
msn = new MSNMessenger(Email,Password);
// set the initial status to online.
// register your pre-created adapter to msn
msn.addMsnListener(new MSNAdapter(msn));
// login into the msn network

System.out.println("Waiting for the response....");

Coding Step 3: Debug or run your application.In the context menu
of project jRCS,??select Run --> Java Application, Eclipse will compile the code
and run the application in the??Console.
If you have your msn account set properly, and you have another msn account that
add this msn account as contact, you will see this msn account log in, and then you can send
some message to this contact as you wishBusiness Management Articles, how ever the Contact will only and always answer
you "How are you doing?".*_^