无法将消息发送到openfire服务器
问题描述:
我无法使用SMACK API在Openfire服务器上向XMPP客户端发送消息。 我不知道我哪里错了。 我在gtalk上测试了相同的代码,它工作正常。无法将消息发送到openfire服务器
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");
}
}
}
它给了我'发送的消息'。 但没有消息到达接收端。
此外,如果“发件人”希望将消息发送给“接收器”那么这是否意味着他们应该被添加到对方的“花名册”
答
您登录到本地主机,但你正在发送信息至[email protected]。你确定这是其他用户的正确的jid吗?我希望它是receiver @ localhost。
AFAIK,聊天并不要求他们彼此间的名单,虽然这是更典型的情况。
答
您检查openfire服务器的错误日志。 您可能会在流标头中看到类似'错误的主机名的错误。主机:example.com' 我已经看到这种类型的错误,如果您的服务器名称是'本地主机',那么您可以在用户之间发送消息,如[email protected],[email protected] ...等
但[email protected]不能将消息发送到[email protected]。
你能更具体一点吗?你有例外吗? .. – Molske 2012-03-20 09:42:40
nope没有例外...它显示“消息发送...” – frewper 2012-03-20 09:50:35
据我记得 - 是的,聊天要求合作伙伴被添加到他们的名册。先尝试一下。如果你有管理员访问openfire服务器,这很容易。 – 2012-03-20 09:53:23