gpt4 book ai didi

java - 无法向 openfire 服务器发送消息

转载 作者:行者123 更新时间:2023-12-04 05:53:33 24 4
gpt4 key购买 nike

我无法使用 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("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");
}
}

}

它给了我一个“消息已发送...”。
但没有消息到达接收端。

此外,如果“发送者”想要向“接收者”发送消息,那么这是否意味着他们应该被添加到彼此的“名单”中

最佳答案

您正在登录 本地主机 ,但您正在向 发送消息接收者@example.com .您确定这是其他用户的正确 jid 吗?我希望它是 接收者@本地主机 .

AFAIK,聊天不需要他们在彼此的名单上,尽管这是更典型的情况。

关于java - 无法向 openfire 服务器发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9784320/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com