2
votes

I am unable to send a message to a XMPP client on an openfire server using SMACK API. I m not sure where i am going wrong. I tested the same code on gtalk and it works fine.

public class SenderTest 
{
public static void main(String args[])
{
    ConnectionConfiguration connConfig = new ConnectionConfiguration("localhost", 5222);
        connConfig.setSASLAuthenticationEnabled(false);
       XMPPConnection connection = new XMPPConnection(connConfig);

        try {
            connection.connect();
            System.out.println("Connected to " + connection.getHost());
        } catch (XMPPException ex) {
            //ex.printStackTrace();
            System.out.println("Failed to connect to " + connection.getHost());
            System.exit(1);
        }
        try {
            connection.login("sender", "a");
            System.out.println("Logged in as " + connection.getUser());

            Presence presence = new Presence(Presence.Type.available);
            connection.sendPacket(presence);

        } catch (XMPPException ex) {
            //ex.printStackTrace();
            System.out.println("Failed to log in as " + connection.getUser());
            System.exit(1);
        }

    ChatManager chatmanager = connection.getChatManager();
    Chat newChat = chatmanager.createChat("[email protected]", new MessageListener() {
        public void processMessage(Chat chat, Message message) {
            System.out.println("Received message: " + message);
        }
    });

    try {
        newChat.sendMessage("Howdy!");
        System.out.println("Message Sent...");
    }
    catch (XMPPException e) {
        System.out.println("Error Delivering block");
    }
}

}

It gives me a 'Message Sent...'. but no message arrives at the receiving end.

Also if 'sender' wants to send a message to 'receiver' then does it mean that they should be added to each other's 'roster'

2
Can you be a bit more specific? Do you get an exception? ..KristofMols
nope no exceptions...it shows "Message sent..."frewper
As far as I remember - yes, chatting requires that the partners are added to their rosters. Give it a try first. It's easy if you have admin access to the openfire server.Andreas Dolk
they are added to each others 'roster', i wasnt sure, thanks for clearing up...frewper

2 Answers

1
votes

You are logging in to localhost, but you are sending a message to [email protected]. Are you sure that is the correct jid for the other user? I would expect that it is receiver@localhost.

AFAIK, chatting does not require that they are on each others rosters, although that is the more typical case.

2
votes

You check the error log of openfire server. You might get the error like 'incorrect hostname in stream header. Host: example.com' I have seen such type of error, if your server name is 'localhost' , then you can send messages between users like [email protected] , [email protected] ...etc

but [email protected] can't send message to [email protected].