tigase客户端通过ip访问 Not able to connect Android client with local XMPP server

原文链接http://stackoverflow.com/questions/3024335/not-able-to-connect-android-client-with-local-xmpp-server

Hi 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.

=========================================================================

网友答复

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");




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值