我使用XMPP创建聊天应用程序:
为此,我使用 eJabberd2 作为服务器, asmack lib(asmack-2010.05.07.jar)作为我的Android应用程序中的客户端,
我可以与主机 talk.google.com 建立联系,但无法与我的eJabberd主机建立联系。
我的代码是:
1)工作正常:
@Override
protected Void doInBackground(Void... arg0) {
ConnectionConfiguration cc = new ConnectionConfiguration( "talk.google.com", 5222, "gmail.com" );
XMPPConnection connection = new XMPPConnection(cc);
try {
SASLAuthentication.supportSASLMechanism("PLAIN");
cc.setSASLAuthenticationEnabled(true);
connection.connect();
Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);
Log.i("XMPPClient", "[SettingsDialog] Connected to "
+ connection.getHost());
} catch (XMPPException e1) {
Log.e("XMPPClient", e1.toString());
}
}
2)不工作:我的eJabberd在http://68.178.255.136:5280/admin/
@Override
protected Void doInBackground(Void... arg0) {
ConnectionConfiguration cc = new ConnectionConfiguration( "68.178.255.136", 5280, "68.178.255.136" );
XMPPConnection connection = new XMPPConnection(cc);
try {
SASLAuthentication.supportSASLMechanism("PLAIN");
cc.setSASLAuthenticationEnabled(true);
connection.connect();
Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);
Log.i("XMPPClient", "[SettingsDialog] Connected to "
+ connection.getHost());
} catch (XMPPException e1) {
Log.e("XMPPClient", e1.toString());
}
}
O / P:
06-06 17:20:27.231: E/XMPPClient(446): Connection failed. No response from server.:
06-06 17:20:27.381: W/System.err(446): java.net.SocketException: Socket closed
06-06 17:20:27.381: W/System.err(446): at org.apache.harmony.luni.platform.OSNetworkSystem.read(Native Method)
06-06 17:20:27.381: W/System.err(446): at dalvik.system.BlockGuard$WrappedNetworkSystem.read(BlockGuard.java:273)
06-06 17:20:27.381: W/System.err(446): at org.apache.harmony.luni.net.PlainSocketImpl.read(PlainSocketImpl.java:458)
06-06 17:20:27.381: W/System.err(446): at org.apache.harmony.luni.net.SocketInputStream.read(SocketInputStream.java:85)
06-06 17:20:27.381: W/System.err(446): at java.io.InputStreamReader.read(InputStreamReader.java:255)
06-06 17:20:27.381: W/System.err(446): at java.io.BufferedReader.read(BufferedReader.java:311)
06-06 17:20:27.381: W/System.err(446): at org.kxml2.io.KXmlParser.peek(KXmlParser.java:925)
06-06 17:20:27.381: W/System.err(446): at org.kxml2.io.KXmlParser.peekType(KXmlParser.java:589)
06-06 17:20:27.381: W/System.err(446): at org.kxml2.io.KXmlParser.nextImpl(KXmlParser.java:333)
06-06 17:20:27.381: W/System.err(446): at org.kxml2.io.KXmlParser.next(KXmlParser.java:1378)
06-06 17:20:27.381: W/System.err(446): at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:326)
06-06 17:20:27.381: W/System.err(446): at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)
06-06 17:20:27.381: W/System.err(446): at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:71)
答案 0 :(得分:4)
我认为问题在于您提供的端口,请使用5222而不是5280,因为在XMPP客户端连接5222而不是5280.