这是关于帖子here
我可以将我的PC连接到本地的本地tigase服务器设置(我正在使用Smack API)。现在,当我想通过Wi-Fi将Android Phone连接到该服务器时,我遇到了问题。我能够通过使用客户端Beem连接到本地服务器android.My XMPP服务器的域名是我的PC名称“mwbn43-1”,IP地址是“192.168.0.221”(我能够ping这个服务器从Android终端模拟器)。在Beem设置中有一个高级选项,我可以在其中指定我想要连接的服务器(我已经将其作为IP地址)。如果我没有设置此选项,我无法conect.Now这里是的片段代码我用于我的Android客户端。
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();
我也可以通过此代码连接到谷歌谈话服务器。虽然与本地服务器建立连接,我尝试提供IP地址和主机名连接。当我给IP地址(192.168.0.221)我得到“没有来自服务器错误的响应”有stream:error(host-unknown),当我给出主机名(mwbn43-1)时,我得到'remote-server-timeout(504)',主机未解析。
我查看了Beem的代码,看看它是如何与服务器连接但找不到太多。我也给了Internet的用户权限。任何人都可以告诉我应该添加什么行代码来与本地服务器通信
答案 0 :(得分:6)
尝试3参数ConnectionConfiguration构造函数。它让你说明主机,端口和域。主机和域不必是相同的值。在你的情况下,我想:
ConnectionConfiguration config =
new ConnectionConfiguration("192.168.0.221",5222,"mwbn43-1");
答案 1 :(得分:2)
尝试从登录呼叫中删除主机名。
例如, 使用
connection.login("username", "password");
而不是
connection.login("username@host.com", "password");
答案 2 :(得分:0)
确保你没有使用它不会在android上运行的本机smack jar尝试使用asmack或其祖先之一android-and-xmpp-currently-available-solutions
答案 3 :(得分:0)
为 ConnectionConfiguration 使用三个参数构造函数。并传递没有主机名扩展名的凭据。
例如,请参阅以下代码:
ConnectionConfiguration config = new ConnectionConfiguration("hostname/IP address", 5222, "servicename/domainname");
connection = new XMPPConnection(config);
connection.connect();
connection.login("user1", "password");`
答案 4 :(得分:0)
检查您是否已声明适当的权限: android.permission.INTERNET对