Ameya Phadke
Ameya Phadke

Reputation: 923

Not able to connect Android client with local XMPP server

This is with regards to post here

I am able to connect my PC to the local tigase server setup locally(I am using Smack API). Now I am facing problems when I want to connect Android Phone to that server over Wi-Fi. I am able to connect to the local server by using client Beem for android.My XMPP Domain name of the server is my PC name "mwbn43-1" and IP address is "192.168.0.221"(I am able to ping this server from Android Terminal Emulator). In Beem Settings there is an Advanced option where I can specify server I want to connect with(which I have given as IP address).If I don't set this option I am not able to conect.Now here is the snippet of the code I have used for my android client.

    XMPPConnection.DEBUG_ENABLED = true;
    ConnectionConfiguration config = new ConnectionConfiguration("mwbn43-1",5222);

    //ConnectionConfiguration config = new ConnectionConfiguration("192.168.0.221",5222);             
    config.setSASLAuthenticationEnabled(false);
    config.setCompressionEnabled(false);

    XMPPConnection xmpp = new XMPPConnection(config);

    try {

            xmpp.connect(); 

            xmpp.login("admin@mwbn43-1", "tigase");
            String host = xmpp.getHost();
            String id = xmpp.getConnectionID();
            int port = xmpp.getPort();
            boolean i = false;
            i = xmpp.isConnected();
            if(i)
            {answer = "Connected to " + host + " via port " + port + " with ID " + id;
            answerfield.setText(answer);}

          }//end try 
    catch (XMPPException e) {  
     answerfield.setText("Failed to connect");
     Log.v(TAG, "Failed to connect to " + xmpp.getHost());
            e.printStackTrace();

I am also able to connect to google talk server with help of this code.While making connection with local server I tried giving IP adress as well as Host Name to connect.When I give IP addr(192.168.0.221) I get 'No response from server error' with stream:error(host-unknown) and when I give host name(mwbn43-1) I get 'remote-server-timeout(504)' with host unresolved.

I looked at the code of Beem to see how it connects with server but could not find much.I have also given user permissions for Internet.Can anyone please tell me what lines of code should I add to communicate with the local server.

Upvotes: 4

Views: 9011

Answers (5)

Goran Horia Mihail
Goran Horia Mihail

Reputation: 3645

Check if you have declared the proper permission: android.permission.INTERNET

Upvotes: 0

Siklab.ph
Siklab.ph

Reputation: 1031

Try removing the host name from the login call.

For example, use

connection.login("username", "password");

instead of

connection.login("[email protected]", "password");

Upvotes: 2

Ahmed Aswani
Ahmed Aswani

Reputation: 8659

Make sure you are not using the native smack jar it wont work on android try to use asmack or one of its ancestors android-and-xmpp-currently-available-solutions

Upvotes: 0

Sridhar Nalam
Sridhar Nalam

Reputation: 547

Use three argument constructor for ConnectionConfiguration. and pass credentials without host name extension.

For example, see below code:

ConnectionConfiguration config = new ConnectionConfiguration("hostname/IP address", 5222, "servicename/domainname");  
connection = new XMPPConnection(config);  
connection.connect();  
connection.login("user1", "password");`

Upvotes: 0

Martín Schonaker
Martín Schonaker

Reputation: 7305

Try 3 argument ConnectionConfiguration constructor. It let's you state host, port and domain. Host and domain doesn't have to be the same values. In you case, I guess:

ConnectionConfiguration config = 
  new ConnectionConfiguration("192.168.0.221",5222,"mwbn43-1");

Upvotes: 6

Related Questions