Reputation: 1433
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'
Upvotes: 2
Views: 2241
Reputation: 385
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].
Upvotes: 2
Reputation: 24282
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.
Upvotes: 1