无法向 openfire 服务器发送消息 [英] Cannot send message to openfire server
问题描述
我无法使用 SMACK API 向 openfire 服务器上的 XMPP 客户端发送消息.我不确定我哪里出错了.我在 gtalk 上测试了相同的代码,它工作正常.
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("receiver@example.com", 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'
推荐答案
您正在登录 localhost,但是您正在向 receiver@example.com.您确定这是其他用户的正确 jid 吗?我希望它是 receiver@localhost.
You are logging in to localhost, but you are sending a message to receiver@example.com. Are you sure that is the correct jid for the other user? I would expect that it is receiver@localhost.
AFAIK,聊天不需要他们在彼此的名单上,尽管这是更典型的情况.
AFAIK, chatting does not require that they are on each others rosters, although that is the more typical case.
这篇关于无法向 openfire 服务器发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!