0

Im trying to connect to Openfire Server using Asmack library 4.0.2.Im failing to get connected to the server even though i had provided correct ip address with the port.

public static final String HOST = "192.168.1.100"; 
public static final int PORT = 9090;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    connect();
        }

public void connect(){
    AsyncTask<Void, Void, Boolean> connectionThread = new AsyncTask<Void, Void, Boolean>(){ 
    @Override
    protected Boolean doInBackground(Void... arg0){
    boolean isConnected = false;

    ConnectionConfiguration config = new ConnectionConfiguration(HOST,PORT);
    config.setReconnectionAllowed(true);
    config.setSecurityMode(SecurityMode.disabled);
    config.setDebuggerEnabled(true);

    XMPPConnection connection = new XMPPTCPConnection(config);

    try{
    connection.connect();
    Log.i("XMPPChatDemoActivity","Connected to " + connection.getHost());
    isConnected = true;
    } catch (IOException e){
        Log.e("XMPPIOExceptionj", e.toString());
    } catch (SmackException e){
        Log.e("XMPPSmackException", e.toString()+" Host:"+connection.getHost()+"Port:"+connection.getPort());
    } catch (XMPPException e){
        Log.e("XMPPChatDemoActivity", "Failed to connect to "
                + connection.getHost());
        Log.e("XMPPChatDemoActivity", e.toString());
    }

    return isConnected;
    }
    };  
    connectionThread.execute();
    } 

And im getting the following error possibly because Host and Port are getting assigned null and 0 respectively even though i had assigned them correctly.Pls help me in sorting out this connection prob.

08-12 22:10:20.496:    E/XMPPSmackException(4341):org.jivesoftware.smack.SmackException$NoResponseException Host:nullPort:0
Dinesh Ps
  • 15
  • 6

2 Answers2

0

Can you confirm that port 9090 is the correct port for XMPP protocol? Default install of Openfire will set port 9090 to be used for accessing the HTTP based configuration console. I recommend you try connecting to the port for XMPP connections as specified on the main index page of the Openfire configuration console (Listed below "Server Ports").

The following is taken from the Openfire configuration console:

5222 The standard port for clients to connect to the server. Connections may or may not be encrypted. You can update the security settings for this port.

fpsColton
  • 873
  • 5
  • 11
  • Have you tried using the 3 argument constructor instead? https://www.igniterealtime.org/builds/smack/docs/latest/javadoc/org/jivesoftware/smack/ConnectionConfiguration.html#ConnectionConfiguration(java.lang.String,%20int,%20java.lang.String) – fpsColton Aug 12 '14 at 19:29
  • The next day i tried it with 5222 and it worked fine..May be it dint work first time coz i din't restart my PC and server after changing the port from 9090 to 5222..Anyways thanks for your help :) – Dinesh Ps Aug 24 '14 at 14:02
  • @fpsColton I am facing problem in connecting android virtual device to xmpp server. I am using this [code](http://paste.ofcode.org/36CSHhtnaEVDUrgqnWMzqW7) to connect to xmpp and i am getting [exception](http://paste.ofcode.org/3b9wT5yeuLB97rfZgZ7eFEZ), can you tell any solution for this? – nawaab saab Jan 16 '15 at 07:07
  • @devil, Having never used smack I'm only speculating, but from what I can see it looks like the constructor for `ConnectionConfiguration` is not able to resolve the hostname 'pc'. I would use the IP of the pc running xmpp server directly. (127.0.0.1 will not work, loops back to the avd) – fpsColton Jan 16 '15 at 16:49
  • @fpsColton thanks for looking that, its solved with [this](http://stackoverflow.com/a/27981613/3409600) solution – nawaab saab Jan 17 '15 at 14:54
  • @fpsColton have you worked on file sharing using xmpp and asmack. If yes, then kindly help in solving this [issue](http://stackoverflow.com/q/28271210/4358880) – Android Rockss Feb 02 '15 at 06:47
0

I think your Host adress is wrong too, you must use the adress to connect openfire server. It must be "127.0.0.1" or just write "localhost". and the port is 5222 to be able to talk from client to server.

mblackplum
  • 15
  • 5