Why can't I connect to the openfire server?

2020-02-13 05:34发布

问题:

I'm having a little bit of trouble trying to connect to Openfire (which I've installed on my computer) while using Smack.

    ConnectionConfiguration config = new ConnectionConfiguration("shin-pc" ,5222);
    config.setCompressionEnabled(true);
    config.setSASLAuthenticationEnabled(true); 
    XMPPConnection connection = new XMPPConnection(config);             
    connection.connect();
    connection.login("test", "test");

When I try debugging or running, there's an error of some sort in the connect() line.

XMPPError connecting to localhost:5222.: remote-server-error(502) XMPPError connecting to localhost:5222. -- caused by: java.net.SocketException: Permission denied.

I've tried switching the host name to "localhost", and it didn't work either.

I have no experience in this XMPP business so I guess it's a common newbie problem or something of the sort...

What might be the problem? How can I fix this so the connection will be successful?

回答1:

I just created a new project in which I need XMPP, and ran into the same problem. However, I realized that it was simply because I had forgotten to add the internet permission in my manifest:

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

Make sure that you haven't done the same mistake.



回答2:

I have Same problem .... but i resolved this issue at my end using following steps :::

1) Firstly checked Internet permission

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

2) Then open the openfire.xml file from C:\Openfire\conf (Installation directory) and edit the file

    <network>
        <interface>Your IP Address(192.168.0.1)</interface>
    </network> 

and save the file and start the openfire server. I think it will be helpful for you....



回答3:

i had the same problem, i followed these steps to solve it:

  1. disable your firewall first

  2. use your the IP address of your server openfire



回答4:

Use host as localhost if you are using a device. If you are using an emulator, use ip address (192.168.1.2 or whatever) in the configuration step (line 1 of the given code)