虽然我可以使用pidgin登录,但我无法通过android仿真器登录到ejabberd服务器。以下是我的android代码,它尽可能少,并且包含一些已弃用的API,仅用于学习目的(我不认为过时的API是问题的一部分,但不是专家,是可以教的)。我已经尝试过this,this和许多others,但是没有解决方案的见解。
Android代码
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.AsyncTask;
import android.os.Bundle;
//import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.chat.Chat;
import org.jivesoftware.smack.chat.ChatManager;
import org.jivesoftware.smack.chat.ChatManagerListener;
import org.jivesoftware.smack.chat.ChatMessageListener;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
import org.jxmpp.stringprep.XmppStringprepException;
import org.minidns.dnsserverlookup.android21.AndroidUsingLinkProperties;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class MainActivity extends AppCompatActivity {
//InetAddress addr = InetAddress.getByName("127.0.0.1");
public MainActivity() throws UnknownHostException {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyLoginTask task = new MyLoginTask();
task.execute("");
}
private class MyLoginTask extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... params) {
// Create a connection to the jabber.org server.
XMPPTCPConnectionConfiguration config = null;
try {
//try {
//AndroidUsingLinkProperties.setup(getApplicationContext());
config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword("cray", "1234")
//.setServiceName()
//.setHost("192.168.0.104")
.setHost("10.0.2.2")
.setXmppDomain("localhost")
//.setHost("localhost")
//.setHostAddress(InetAddress.getByName("localhost"))
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
//.setServiceName("localhost")
.setPort(5280)
//.setDebuggerEnabled(true) // to view what's happening in detail
.build();
//} catch (UnknownHostException e) {
// e.printStackTrace();
//}
} catch (XmppStringprepException e) {
//e.printStackTrace();
Log.e("XMMP_APP", "Exception", e);
}
AbstractXMPPConnection conn1 = new XMPPTCPConnection(config);
try {
conn1.connect();
if(conn1.isConnected())
{
Log.w("app", "------connetion successful-------");
}
conn1.login();
if(conn1.isAuthenticated())
{
Log.w("app", "Auth done");
ChatManager chatManager = ChatManager.getInstanceFor(conn1);
chatManager.addChatListener(
new ChatManagerListener() {
@Override
public void chatCreated(Chat chat, boolean createdLocally)
{
chat.addMessageListener(new ChatMessageListener()
{
@Override
public void processMessage(Chat chat, Message message) {
System.out.println("Received message: "
+ (message != null ? message.getBody() : "NULL"));
}
});
Log.w("app", chat.toString());
}
});
}
}
catch (Exception e) {
//Log.w("app", e.toString());
Log.e("XMMP_APP", "Exception", e);
}
return "";
}
@Override
protected void onPostExecute(String result) {
// execution of result of Long time consuming operation
}
}
}
我尝试确认用户是否使用 ejabberdctl connected_user_number 或仅使用 ejabberdctl connected_user 登录了ejabberd服务器,但是我看不到任何用户登录使用pidgin客户端轻松登录。
这是错误(堆栈跟踪)
08-23 11:57:10.981 2681-2681/? I/art: Not late-enabling -Xcheck:jni (already on)
08-23 11:57:11.002 2681-2687/? E/art: Failed writing handshake bytes (-1 of 14): Broken pipe
08-23 11:57:11.002 2681-2687/? I/art: Debugger is no longer active
08-23 11:57:11.002 2681-2681/? W/System: ClassLoader referenced unknown path: /data/app/com.comcast.redfire-1/lib/x86
08-23 11:57:11.067 2681-2681/? W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
08-23 11:57:13.853 2681-2681/com.comcast.redfire I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>
08-23 11:57:13.853 2681-2681/com.comcast.redfire I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>
08-23 11:57:14.052 2681-2704/com.comcast.redfire D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
08-23 11:57:14.093 2681-2704/com.comcast.redfire I/OpenGLRenderer: Initialized EGL, version 1.4
08-23 11:57:14.095 2681-2704/com.comcast.redfire W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
08-23 11:57:14.292 2681-2704/com.comcast.redfire D/EGL_emulation: eglCreateContext: 0xb405abc0: maj 2 min 0 rcv 2
08-23 11:57:14.307 2681-2704/com.comcast.redfire D/EGL_emulation: eglMakeCurrent: 0xb405abc0: ver 2 0 (tinfo 0xaff49510)
08-23 11:57:14.424 2681-2704/com.comcast.redfire D/EGL_emulation: eglMakeCurrent: 0xb405abc0: ver 2 0 (tinfo 0xaff49510)
08-23 11:57:30.872 2681-2703/com.comcast.redfire W/app: org.jivesoftware.smack.SmackException$ConnectionException: The following addresses failed: '10.0.2.2:5222' failed because: org.minidns.util.MultipleIoException: null, failed to connect to /10.0.2.3 (port 53) after 5000ms: isConnected failed: ECONNREFUSED (Connection refused), null, failed to connect to /8.8.8.8 (port 53) after 5000ms: isConnected failed: ENETUNREACH (Network is unreachable), sendto failed: ENETUNREACH (Network is unreachable), failed to connect to /2001:4860:4860::8888 (port 53) after 5000ms: connect failed: ENETUNREACH (Network is unreachable), null, failed to connect to g.root-servers.net/192.112.36.4 (port 53) after 5000ms: isConnected failed: ENETUNREACH (Network is unreachable), sendto failed: ENETUNREACH (Network is unreachable), failed to connect to i.root-servers.net/2001:7fe::53 (port 53) after 5000ms: connect failed: ENETUNREACH (Network is unreachable)
我在清单文件中添加了Internet权限
将http:// localhost:5222更改为http://127.0.0.1:5222更改为http://10.0.2.2:5222更改为http://127.0.0.1 甚至http://192.168.x.xxx:522都没有成功
我什至更改了gradle以添加此行
实现'de.measite.minidns:minidns-hla:0.2.4'
不变:(
我已使缓存无效,并多次重启了应用程序。
有人可以帮我解决这个难题吗?谢谢您的时间和关注。很抱歉,格式不正确且信息不完整。
我认为问题出在10.0.2.2。由于我使用的是Android模拟器,因此建议不要使用127.0.0.1,而应使用10.0.2.2。如您所见,10.0.2.2不会发送回数据包。如何解决此问题?
答案 0 :(得分:0)
很可能您没有有效的DNS设置。我强烈建议您将ejabberd安装在具有正确网络设置并且最重要的是域+有效证书的服务器上。