1
votes

I implemented new Smack 4.2 with Ejabberd I'm getting connection closed on error if I don't login or register as I want to create a connection before login or register. The same code is working fine with Openfire server.

I'm getting this error in a few seconds (nearly 30 seconds) when connection is created. Connection XMPPTCPConnection[not-authenticated] (0) closed with error org.jivesoftware.smack.XMPPException$StreamErrorException: connection-timeout You can read more about the meaning of this stream error at http://xmpp.org/rfcs/rfc6120.html#streams-error-conditions

On re-connection it is crashing with this error

FATAL EXCEPTION: Smack Reconnection Manager (0) java.lang.IllegalArgumentException: Username must not be null or empty at org.jivesoftware.smack.util.StringUtils.requireNotNullOrEmpty(StringUtils.java:468) at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:484) at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:448) at org.jivesoftware.smack.ReconnectionManager$2.run(ReconnectionManager.java:254) at java.lang.Thread.run(Thread.java:818)

Some lines of code of configuration

 if (connection == null || !connection.isConnected()) {
        XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration
                .builder();
        config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
        DomainBareJid serviceName = JidCreate.domainBareFrom(Constants.SERVER_NAME);
        config.setServiceName(serviceName);
        InetAddress inetAddress = InetAddress.getByName(Constants.HOST);
        config.setXmppDomain(Constants.SERVER_NAME);
        config.setHostAddress(inetAddress);
        config.setHost(Constants.HOST);
        config.setPort(Constants.PORT);
        config.setResource(Constants.RESOURCE);
        config.setDebuggerEnabled(true);
        SASLAuthentication.blacklistSASLMechanism("PLAIN");
        SASLAuthentication.blacklistSASLMechanism("DIGEST-MD5");
        SASLAuthentication.unBlacklistSASLMechanism("SCRAM-SHA-1");
        XMPPTCPConnection.setUseStreamManagementDefault(true);
        connection = new XMPPTCPConnection(config.build());
        initializingMessageReceivedListeners();
        enableReConnection();
        connection.connect();
    }

Thanks in advance.

1
why don't add some code?MrPk
Check Your username is null or empty while doing connection. Log clearly mentioned that username is null or empty.Keyur Thumar
Actually I want to create connection before login and registration. Even the connection is created but breaks in a few seconds. Creating the connection before save time while doing login and registration. This is also working fine with Openfire do I need to do any config changes with EjabberdNeha

1 Answers

0
votes

Found the solution to my own question Openfire allows connection to be created even when you don't login but Ejabberd breaks after a few seconds but we can delay this time.