4

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.

Community
  • 1
  • 1
Ameya Phadke
  • 923
  • 1
  • 13
  • 18
  • It can be a Tigase issue. I can't connect to my Tigase server from Pidgin and Empathy with getting the "host-unknown" error. It used to work from jabberd. – v6ak Oct 02 '11 at 18:25
  • This solution WORKED FOR ME !! If you are using Android device to connect to XMPP server(ejabberd in my case), you have to use ASmack jar instead of Smack jar. If your XMPP server is installed locally and if you are connecting over WIFI, you need to use 3 argument ConnectionConfiguration constructor. The first argument HOST needs your LOCAL WIFI IP Address(be very careful with that), second argument port will be 5222 and third argument should be the XMPP server name you created while installing it. Then for connection.login("username", "password") you can simple use username like admin. – Hari Gudigundla Apr 01 '14 at 06:54
  • possible duplicate of ['remote-server-timeout' exception as I try to connect to the server](http://stackoverflow.com/questions/18285323/remote-server-timeout-exception-as-i-try-to-connect-to-the-server) – Flow Jan 16 '15 at 10:49

5 Answers5

6

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");
Martín Schonaker
  • 7,273
  • 4
  • 32
  • 55
  • 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:11
  • No clue. Ask it as another question. – Martín Schonaker Jan 16 '15 at 12:56
  • thanks for looking that, its solved with [this](http://stackoverflow.com/a/27981613/3409600) solution – nawaab saab Jan 17 '15 at 14:54
2

Try removing the host name from the login call.

For example, use

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

instead of

connection.login("username@host.com", "password");
Hitesh Patel
  • 2,868
  • 2
  • 33
  • 62
Siklab.ph
  • 991
  • 11
  • 17
  • @Hitesh Patel 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:10
0

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

Goran Horia Mihail
  • 3,536
  • 2
  • 29
  • 40
  • 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:09
0

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

Community
  • 1
  • 1
Ahmed Aswani
  • 8,271
  • 7
  • 33
  • 54
0

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");`
Hitesh Patel
  • 2,868
  • 2
  • 33
  • 62
Sridhar Nalam
  • 527
  • 8
  • 9