我使用的是erlang 17.0,ejabberd 14.07。我正在尝试创建聊天应用程序,我已经完成了注册部分。现在我想从注册用户登录,但我无法登录,所以如何在ejabberd上以用户身份登录。 基本上我的问题是,用户如何成为ejabberd服务器上的在线服务器(在localhost上)?
我知道这是一个非常愚蠢的问题,但我无法找到任何方式来引导我。
答案 0 :(得分:0)
使用函数yourconnection.login(用户名,密码)。
答案 1 :(得分:0)
首先确保使用命令
在ejabberd上成功注册了用户> sudo ejabberdctl registered_users localhost
这将列出localhost节点上的所有注册用户。希望你能在那里找到你的用户。
现在,您已成功设置了ejabberd(XMPP服务器)。您需要XMPP客户端才能让用户登录。
因此,如果您使用的是java编程语言,则应使用SMACK XMPP库连接到ejabberd服务器。将此代码与您的用户名和密码一起使用即可连接到ejabberd服务器。
// Create a connection to the igniterealtime.org XMPP server.
XMPPTCPConnection con = new XMPPTCPConnection("igniterealtime.org");
// Connect to the server
con.connect();
// Most servers require you to login before performing other tasks.
con.login("jsmith", "mypass");
// Start a new conversation with John Doe and send him a message.
Chat chat = ChatManager.getInstanceFor(con).createChat("jdoe@igniterealtime.org", new MessageListener() {
public void processMessage(Chat chat, Message message) {
// Print out any messages we get back to standard out.
System.out.println("Received message: " + message);
}
});
chat.sendMessage("Howdy!");
// Disconnect from the server
con.disconnect();
有关此代码的更多详细信息,请访问sounddevice。
如果你想使用Java之外的客户端,那么这里是link
连接到ejabberd服务器后,您需要保持该连接以进一步发送和接收消息。