CantThinkOfAnything CantThinkOfAnything - 1 year ago 116
Java Question

XMPP register new user

I am having lots of trouble with XMPP, I am new to it and all the examples that I have found already have an account with which they connect and then do things.

My problem concerns new users. Someone who does not have an account needs to be able to register himself and then log in. But as I have understood, you first need to create a connection before you can create users. So without an account you can not create one.

some links I have been reading:

So basically, I need to create a connection without user login. Then create a user and login with the user.

So I found this:

How to register a new user on XMPP using asmack library

But it seems that the AccountManager class is outdated or something because I cannot find it in the same path. (

So the question is: How do I create a new account and then login with it(from a new users perspective)?

A small code snippet or a link to some source would be highly appreciated.

I have gotten to this point:

XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()

XMPPConnection connection = new XMPPTCPConnection(config);

now I need to instantiate an AccountManager object but its not available in smack 4.1

I am trying to follow this example: How to create an account from Smack 4.1

and even though I read that it should be in smackx. The only thing I can find in smackx is:


Answer Source

Creating an account works by first connecting to the server and then initializing the account creation. Essentially, you create a connection in which you can create an account, and then proceed to create said account. Here's how I do it:

XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration.builder()

AbstractXMPPConnection connection = new XMPPTCPConnection(conf);
connection.connect(); // Here we create the connection

// Now we create the account:
AccountManager accountManager = AccountManager.getInstance(connection);
accountManager.createAccount(username, password);

// The account has been created, so we can now login
connection.login(username, password);

So we first initialized the connection, created the account, and then logged in. Hopefully this helps

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download