Unable to connect with ejabberd using smack 4.1 android

I setup ejabberd on localhost which have domain name is "arpit-pc" but when I try to connect with ejabberd using smack 4.1 client in android** then I am getting following error mentioned below

05-28 11:32:30.561 10869-10891/com.example.arpit.openfire W/System.err: org.jivesoftware.smack.SmackException$ConnectionException: The following addresses failed: 'arpit-pc:5222' failed because: arpit-pc/192.168.43.69 exception: java.net.SocketTimeoutException: connect timed out

Code that I have written you can see below

package com.example.arpit.openfire;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import android.util.Log;

import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
import org.jivesoftware.smackx.iqregister.AccountManager;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import android.os.AsyncTask;

/**
* Created by Arpit on 5/25/2017.
*/
import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
import org.jivesoftware.smackx.iqregister.AccountManager;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.jid.parts.Localpart;
import org.jxmpp.stringprep.XmppStringprepException;

import android.util.Log;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MainActivity extends AppCompatActivity {
    public static final String TAG = "hellloooooo************";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
                Log.e("Error"+Thread.currentThread().getStackTrace()[2],paramThrowable.getLocalizedMessage());
            }
        });
        setContentView(R.layout.activity_main);
        new ConnectToServer().execute("http://example.com/image.png");

    }

    class ConnectToServer extends AsyncTask {
        public static final String TAG = "android smack client-";
        AbstractXMPPConnection connection = null;

        @Override
        protected void onPostExecute(Object o) {
            super.onPostExecute(o);

        }

        @Override
        protected AbstractXMPPConnection doInBackground(Object[] params) {
            XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
            configBuilder.setUsernameAndPassword("admin@arpit-pc", "12345");
            configBuilder.setSecurityMode(XMPPTCPConnectionConfiguration.SecurityMode.disabled);
            //   configBuilder.setResource("testServices");
            try {
                // DomainBareJid serviceName = JidCreate.domainBareFrom("10.113.145.205");
                // configBuilder.setServiceName(serviceName);
                configBuilder.setXmppDomain("arpit-pc");
            }catch(Exception e){

                e.printStackTrace();
                Log.e(TAG, e.toString());
            }
            configBuilder.setPort(5222);
            configBuilder.setHost("arpit-pc");
            configBuilder.setDebuggerEnabled(true);
            connection = new XMPPTCPConnection(
                    configBuilder.build());
            /** Connecting to the server */
            try {

                Log.e(TAG, "build started");

                connection.connect().login();//.login();
                Log.e(TAG, "connected" + connection.getHost());
            } catch (SmackException e) {

                e.printStackTrace();
                Log.e(TAG, "Failed to connereretetrect to 3"+e.getLocalizedMessage()+"------"+e.getCause());
                Log.e(TAG, "Failed to connect to 5" + connection.getHost());
            } catch (IOException e) {
                e.printStackTrace();
                Log.e(TAG, "Failed to connereretetrect to 4" + e);
                Log.e(TAG, "Failed to connect to " + connection.getHost());
            } catch (XMPPException e) {
                Log.e(TAG, "Failed to connect to " + connection.getHost());
                Log.e(TAG, e.toString());
                e.printStackTrace();
            }catch(InterruptedException e){
                Log.e(TAG, "Failed to connect to " + connection.getHost());
                Log.e(TAG, e.toString());
                e.printStackTrace();
            }
            //connection.disconnect();

            return connection;
        }
    }

}

Syndicate content