powered by Jive Software

How to Get offline messages asmack (Android) real time

Hi I’m newbie on openfire .

I have offline messages option enabled in the openfire server.

User A is online ,User B is online in this case I’m able to get messages.

Now User B Turned off his WiFi(Note : User A waited till the user B Session completely killed in the server ) now User A sent a message to User B.
Now User B Comes online again server is sending the message to user B at time 10 minutes.

My code:

 private class MyLoginTask extends AsyncTask<String, String, String> {
        protected String doInBackground(String... params) {
            // Create a connection to the jabber.org server.
            realm = Realm.getDefaultInstance();
            dataUsers = realm.where(EntityUsers.class).findFirst();
            if (dataUsers != null) {
                userName2 = dataUsers.getUsername();
                password = dataUsers.getPass();

            new Thread() {
                public void run() {
                        InetAddress addr = null;
                    try {
                        // inter your ip4address now checking it
                        addr = InetAddress.getByName(domainAddress);
                    } catch (UnknownHostException e) {
                    HostnameVerifier verifier = new HostnameVerifier() {
                        public boolean verify(String hostname, SSLSession session) {
                            return false;
                    DomainBareJid serviceName = null;
                    try {
                        serviceName = JidCreate.domainBareFrom(domainAddress);
                    } catch (XmppStringprepException e) {
                    XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
                            .setUsernameAndPassword(userName2, password)//userName2,"spinku12345"
                    mConnection = new XMPPTCPConnection(config);
                    try {
                        // all these proceedure also thrown error if you does not seperate this thread now we seperate thread create
                        if(mConnection.isConnected()) {
                            Log.w("app", "conn done");

                        if (mConnection.isAuthenticated() && mConnection.isConnected()) {
                            //now send message and receive message code here
                            Log.e(TAG, "run: auth done and connected successfully");
                            ChatManager chatManager = ChatManager.getInstanceFor(mConnection);
                            chatManager.addListener(new IncomingChatMessageListener() {
                                public void newIncomingMessage(EntityBareJid from, Message message, Chat chat) {
                                    Log.e(TAG, "New message from " + from + ": " + message.getBody());
//                                MessagesData data = new MessagesData("received",message.getBody().toString());
//                                final MessagesData data = new MessagesData(userName1 + "@" + serverName, message.getBody().toString());//received
                                    final MessagesData data = new MessagesData("(" + getTime() + ")" + userName1, message.getBody().toString(), 0);//received
                                    //now update recyler view
                                    runOnUiThread(new Runnable() {
                                        public void run() {
                                            //this ui thread important otherwise error occur
                                            mAdapter = new Adapter(mMessagesData);
//                                        setupChatMessages();
                    } catch (SmackException e) {
                    } catch (IOException e) {
                    } catch (XMPPException e) {
                    } catch (InterruptedException e) {


            return "";

How to setup a server to sending offline messages in real time.

Openfire should send offline messages without any delay, once a client connects to the server. There should be something missing in your code dealing with https://xmpp.org/extensions/xep-0203.html
Also, move this topic to Smack Support as this has nothing to do with Openfire and you might get better help there (press the pencil besides the title of this topic and choose a category).

what should I do.
I’m newbie on Smack.

This topic was automatically closed 62 days after the last reply. New replies are no longer allowed.