gpt4 book ai didi

android - 使用 Smack 4.1 连接到 Gtalk

转载 作者:行者123 更新时间:2023-11-30 02:15:11 25 4
gpt4 key购买 nike

我正在尝试使用 Smack 4.1 从我的 Android 应用程序连接到 Gtalk,但每次我尝试连接时,它都会显示错误:javax.net.ssl.SSLHandshakeException:握手失败

下面是我的代码:

private class ConnectionThread extends AsyncTask<Void, Void, Boolean> {

@Override
protected Boolean doInBackground(Void... params) {
boolean isConnected = false;
XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration
.builder();

config.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
config.setUsernameAndPassword(username,password);
config.setServiceName(service);
config.setHost(host);
config.setPort(port);
config.setDebuggerEnabled(true);
//config.setCompressionEnabled(false);
config.setSocketFactory(SSLSocketFactory.getDefault());

connection = new XMPPTCPConnection(config.build());

XMPPConnectionListener connectionListener = new XMPPConnectionListener();
connection.addConnectionListener(connectionListener);

try {
connection.connect();

isConnected = true;
} catch (Exception e) {
Log.e(TAG,"Unable to connect to server = " + e.toString());
}
return isConnected;
}

}

主机、用户名、密码服务和端口来自 String.xml 值:

<?xml version="1.0" encoding="utf-8"?>

<string name="app_name">XmppLab</string>
<string name="action_settings">Settings</string>
<string name="connect">Connect</string>
<string name="host">talk.google.com</string>
<string name="port">5222</string>
<string name="username">username@gmail.com</string>
<string name="password">password</string>
<string name="service">gmail.com</string>

请问我在这里遗漏了什么吗?非常感谢您提供的任何帮助。

最佳答案

感谢提示。我如下更改我的代码,现在它可以连接到 Gtalk:

config.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
config.setUsernameAndPassword(username,password);
config.setServiceName(service);
config.setHost(host);
config.setPort(port);
config.setDebuggerEnabled(true);
//config.setCompressionEnabled(false);
//config.setSocketFactory(SSLSocketFactory.getDefault());

关于android - 使用 Smack 4.1 连接到 Gtalk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29487436/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com