我无法使用 SMACK API 向 openfire 服务器上的 XMPP 客户端发送消息。
我不确定我哪里出错了。
我在 gtalk 上测试了相同的代码,它工作正常。
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] /cdn-cgi/l/email-protection", 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");
}
}
}
它给我一条“消息已发送...”。
但没有消息到达接收端。
此外,如果“发送者”想要向“接收者”发送消息,那么这是否意味着他们应该被添加到彼此的“名册”中
你检查openfire服务器的错误日志。
您可能会收到类似的错误'流头中的主机名不正确。主机:example.com'我见过这种类型的错误,如果您的服务器名称是 'localhost' ,那么您可以在用户之间发送消息,例如[电子邮件受保护] /cdn-cgi/l/email-protection , [电子邮件受保护] /cdn-cgi/l/email-protection ...etc
but [电子邮件受保护] /cdn-cgi/l/email-protection无法发送消息至[电子邮件受保护] /cdn-cgi/l/email-protection.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)