java.net.UnknownHostException while connecting ope

2019-01-29 11:00发布

问题:

I am a beginner for chat app. I started studing regarding chat app I am trying to connect android virtual device to openfire xmpp server, but am unable to connect, I am getting java.net.UnknownHostException can anyone help me in connecting my android device top xmpp server

The code I am using is:

ConnectionConfiguration config = new ConnectionConfiguration("pc" ,5222);
    /*ConnectionConfiguration config = 
        new ConnectionConfiguration("192.168.0.1",5222,"pc");*/
    /*config.setCompressionEnabled(true);
       config.setSASLAuthenticationEnabled(true); */
    config.setSecurityMode(SecurityMode.disabled);
    config.setDebuggerEnabled(true);
    config.setSASLAuthenticationEnabled(false);
       XMPPConnection connection = new XMPPConnection(config);   
       Log.i("", "before connecting");
       connection.connect();
       Log.i("", "after connecting");
       //connection.login("test", "test");
    if(connection.isConnected()){
     System.out.println("connection built");
     connection.disconnect();
    }

in manifest:

<uses-permission android:name="android.permission.INTERNET"/>

and Logcat I got is with java.net.UnknownHostException.

回答1:

We've come across a solution, @devil and I. We simply used IPv4 address of his server.

ConnectionConfiguration config = 
new ConnectionConfiguration("192.168.1.2",5222,"pc");