我試圖製作一個使用XMPP將消息發送到Gmail帳戶的應用程序。我找到了一個提到谷歌XMPP服務器名稱的鏈接,但我不認爲我能夠建立連接。使用smack的Android XMPP:服務器沒有響應
編輯我改變了服務器的名稱,我相信它能夠建立連接。但它表示Rosters有0個條目。我正嘗試使用Gmail帳戶登錄。新的異常我:
07-05 14:02:05.099: W/System.err(13903): java.security.KeyStoreException: java.security.NoSuchAlgorithmException: KeyStore jks implementation not found
07-05 14:02:05.099: W/System.err(13903): at java.security.KeyStore.getInstance(KeyStore.java:119)
07-05 14:02:05.099: W/System.err(13903): at org.jivesoftware.smack.ServerTrustManager.<init>(ServerTrustManager.java:70)
07-05 14:02:05.099: W/System.err(13903): at org.jivesoftware.smack.XMPPConnection.proceedTLSReceived(XMPPConnection.java:824)
07-05 14:02:05.099: W/System.err(13903): at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:267)
07-05 14:02:05.099: W/System.err(13903): at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:43)
07-05 14:02:05.099: W/System.err(13903): at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)
07-05 14:02:05.099: W/System.err(13903): Caused by: java.security.NoSuchAlgorithmException: KeyStore jks implementation not found
07-05 14:02:05.099: W/System.err(13903): at org.apache.harmony.security.fortress.Engine.notFound(Engine.java:177)
07-05 14:02:05.099: W/System.err(13903): at org.apache.harmony.security.fortress.Engine.getInstance(Engine.java:151)
07-05 14:02:05.099: W/System.err(13903): at java.security.KeyStore.getInstance(KeyStore.java:116)
07-05 14:02:05.099: W/System.err(13903): ... 5 more
原來這裏是例外:
07-05 13:30:23.444: W/System.err(12434): at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:306)
07-05 13:30:23.454: W/System.err(12434): at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)
07-05 13:30:23.454: W/System.err(12434): at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:76)
07-05 13:30:38.229: D/Smack(12434): Start Login
07-05 13:30:43.235: E/Smack(12434): Error: No response from the server.
07-05 13:30:43.235: W/System.err(12434): No response from the server.:
07-05 13:30:43.235: W/System.err(12434): at org.jivesoftware.smack.NonSASLAuthentication.authenticate(NonSASLAuthentication.java:58)
07-05 13:30:43.235: W/System.err(12434): at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:232)
07-05 13:30:43.245: W/System.err(12434): at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:341)
07-05 13:30:43.245: W/System.err(12434): at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:301)
07-05 13:30:43.255: W/System.err(12434): at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:283)
07-05 13:30:43.255: W/System.err(12434): at com.example.xmpp.MessageTask.doInBackground(MessageTask.java:33)
07-05 13:30:43.255: W/System.err(12434): at com.example.xmpp.MessageTask.doInBackground(MessageTask.java:1)
07-05 13:30:43.265: W/System.err(12434): at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-05 13:30:43.265: W/System.err(12434): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-05 13:30:43.275: W/System.err(12434): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-05 13:30:43.275: W/System.err(12434): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-05 13:30:43.275: W/System.err(12434): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-05 13:30:43.285: W/System.err(12434): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-05 13:30:43.285: W/System.err(12434): at java.lang.Thread.run(Thread.java:856)
這裏是我的代碼:
ConnectionConfiguration config = new ConnectionConfiguration("xmpp.l.google.com", 5222);
XMPPConnection connection = new XMPPConnection(config);
try {
Log.d("Smack", "Start Connect");
connection.connect();
Log.d("Smack", "Start Login");
connection.login(user, pwd);
Roster roster = connection.getRoster();
//Get all rosters
Collection<RosterEntry> entries = roster.getEntries();
//loop through
Log.d("Smack", "Start Rosters");
for (RosterEntry entry : entries) {
//example: get presence, type, mode, status
Presence entryPresence = roster.getPresence(entry.getUser());
String status = entryPresence.getStatus();
Toast.makeText(context, status, Toast.LENGTH_LONG).show();
Log.d("Smack", "Print rosters");
}
Log.d("Smack", "End Rosters");
} catch (XMPPException e) {
// TODO Auto-generated catch block
Log.e("Smack", "Error: " + e.getMessage());
e.printStackTrace();
}
你有沒有試着用比谷歌的其他XMPP服務器上測試它?谷歌正在開始從XMPP切換到環聊應用的新協議。 **請嘗試xmpp.l.google.com,並告訴我它是否有效** – Vannen
我嘗試過使用該服務器,並且收到了上面發佈的異常。我只是使用錯誤的谷歌服務器?我目前正在嘗試使用Google帳戶登錄。 – AndroidDev93
有一個名爲Beem的項目,它也使用asmack進行XMPP連接,並且它是開源的。你可以嘗試一下,看看它是否仍然適用於Google Talk。 ** http://beem-project.com/projects/beem/files ** – Vannen