powered by Jive Software

Problem with sending messages to online facebook friends using Smack

Hey I am working on making an XMPP client for facebook…I am a newbie to Java . The login part and roster part is working fine for me but when i came to sending messages to my friends online Its not going.I am not getting any errors or other things.Its displaying as if it is sent.But my friends are not getting them.Can u please help me.I have included the code here…Please help me

import java.util.*;

import java.io.*;

import org.jivesoftware.smack.Chat;

import java.lang.String;

import javax.swing.*;

import org.jivesoftware.smack.filter.*;

import org.jivesoftware.smack.ConnectionConfiguration;

import org.jivesoftware.smack.MessageListener;

import org.jivesoftware.smack.Roster;

import org.jivesoftware.smack.RosterListener;

import org.jivesoftware.smack.RosterEntry;

import org.jivesoftware.smack.XMPPConnection;

import org.jivesoftware.smack.XMPPException;

import org.jivesoftware.smack.packet.Message;

import org.jivesoftware.smack.packet.Presence;

import org.jivesoftware.smack.PacketListener;

import org.jivesoftware.smack.SASLAuthentication;;

public class xmppchatclientfirsttry{

XMPPConnection connection;

public void login()throws XMPPException{

SASLAuthentication.registerSASLMechanism(“DIGEST-MD5”, MySASLDigestMD5Mechanism.class);

connection = new XMPPConnection(“chat.facebook.com”);

connection.connect();

System.out.println(“OMG it connected”);

try{

connection.login(“username”,“password”);

System.out.println(connection.getUser());

System.out.println(connection.isAuthenticated());

System.out.println(“Logged in”);

displayBuddyList();

    Chat chat = connection.getChatManager().createChat("1000xxxxxxxxxxx@chat.facebook.com", new MessageListener() {

public void processMessage(Chat chat, Message message) {

System.out.println("Received message: " + message);

}

});

try{

    Message msgObj = new Message("XXXXXXXXXXXXX@chat.facebook.com", Message.Type.chat);

msgObj.setBody(“Hello”);

chat.sendMessage(msgObj);

System.out.println(“Sent Message”);

}catch(XMPPException ep){

System.out.println(“Didnt send message”);

}

}catch(XMPPException e){

System.out.println(“Sad Fuck”);

}

System.out.println(“Disconnecting”);

connection.disconnect();

System.out.println(“Disconnected”);

}

public void displayBuddyList()

{

int h=0;

Roster roster = connection.getRoster();

Collection entries = roster.getEntries();

System.out.println("\n\n" + entries.size() + " buddy(ies):");

for(RosterEntry r:entries)

{

Presence presence = roster.getPresence(r.getUser());

if(presence.getType()==Presence.Type.available){

h++;

System.out.print(r.getUser());

System.out.println(roster.getPresence(r.getUser()));

}

}

System.out.println(h+“buddies”);

}

public static void main(String[] args)throws XMPPException, IOException{

xmppchatclientfirsttry xm=new xmppchatclientfirsttry();

xm.login();

}

}