I am trying to make aSmack work in my project.
Created a standard project in eclipse, added the jar to build path / libraries. Started using the XMPP classes, but I am not sure if there's something else I should do to properly set up the project (later on that), since it's not working.
In a Service
, I start an AsnycTask
to connect to google talk and send one chat message.
conn1 = new XMPPConnection(config);
// connecting to the server
try {
conn1.connect();
Log.v(LOG_TAG, "XMPP connected");
} catch (XMPPException xe) {
msg = "XMPPException during connect(): " + xe.getMessage();
Log.v(LOG_TAG, msg);
}
// login
try {
conn1.login(USERNAME, PASSWORD, RESOURCE);
msg = "login ok";
Log.v(LOG_TAG, msg);
} catch (XMPPException xe) {
msg = "XMPPException login(): " + xe.getMessage();
Log.v(LOG_TAG, msg);
StackTraceElement[] st = xe.getStackTrace();
for (int i = 0; i<st.length; i++) {
msg = xe.getStackTrace()[i].toString();
Log.v(LOG_TAG, msg);
}
}
// creating a chat and sending messages
try {
ChatManager chatmanager = conn1.getChatManager();
msg = "creating chat";
Log.v(LOG_TAG, msg);
Chat chat = chatmanager.createChat(BUDDY_ADDRESS, new MessageListener() {
@Override
public void processMessage(Chat chat, Message message) {
String msg = "incoming chat: " + message;
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG);
Log.v(LOG_TAG, msg);
}
});
chat.sendMessage("ahoj");
} catch (XMPPException xe) {
msg = "XMPPException during connect(): " + xe.getMessage();
Log.v(LOG_TAG, msg);
}
(Please overlook my stupid exception handling, I'm still learning it :-) The connect() method should work, since it doesn't throw an exception, in the Logcat howewer, before the "XMPP connected" message, there's an error, and then an exception thrown by the login() method:
03-01 15:13:19.970: WARN/System.err(4465): stream:error (text)
03-01 15:13:19.970: WARN/System.err(4465): at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:261)
03-01 15:13:19.970: WARN/System.err(4465): at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)
03-01 15:13:19.975: WARN/System.err(4465): at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:71)
03-01 15:13:24.640: DEBUG/dalvikvm(3089): GC_EXPLICIT freed 610 objects / 39760 bytes in 216ms
03-01 15:13:26.370: DEBUG/NetworkLocationProvider(2020): onDataConnectionStateChanged 3
03-01 15:13:26.380: DEBUG/MobileDataStateTracker(2020): replacing old mInterfaceName (pdp0) with pdp0 for hipri
03-01 15:13:26.395: DEBUG/MobileDataStateTracker(2020): replacing old mInterfaceName (pdp0) with pdp0 for supl
03-01 15:13:26.400: DEBUG/MobileDataStateTracker(2020): default Received state= CONNECTED, old= CONNECTED, reason= (unspecified), apnTypeList= default,supl
03-01 15:13:31.570: DEBUG/dalvikvm(2806): GC_EXPLICIT freed 173 objects / 10752 bytes in 207ms
03-01 15:13:34.550: VERBOSE/Smacktest_01(4465): XMPP connected
03-01 15:13:36.600: DEBUG/dalvikvm(2583): GC_EXPLICIT freed 1551 objects / 87688 bytes in 236ms
03-01 15:13:39.580: VERBOSE/Smacktest_01(4465): XMPPException login(): No response from the server.
03-01 15:13:39.585: VERBOSE/Smacktest_01(4465): org.jivesoftware.smack.NonSASLAuthentication.authenticate(NonSASLAuthentication.java:73)
03-01 15:13:39.605: VERBOSE/Smacktest_01(4465): org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:369)
03-01 15:13:39.605: VERBOSE/Smacktest_01(4465): org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:230)
03-01 15:13:39.620: VERBOSE/Smacktest_01(4465): com.biroalex.smacktest_01.SmackTest_01Service$AsyncXMPPConn.doInBackground(SmackTest_01Service.java:105)
03-01 15:13:39.620: VERBOSE/Smacktest_01(4465): com.biroalex.smacktest_01.SmackTest_01Service$AsyncXMPPConn.doInBackground(SmackTest_01Service.java:1)
03-01 15:13:39.635: VERBOSE/Smacktest_01(4465): android.os.AsyncTask$2.call(AsyncTask.java:185)
03-01 15:13:39.640: VERBOSE/Smacktest_01(4465): java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
03-01 15:13:39.655: VERBOSE/Smacktest_01(4465): java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-01 15:13:39.655: VERBOSE/Smacktest_01(4465): java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
03-01 15:13:39.660: VERBOSE/Smacktest_01(4465): java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
03-01 15:13:39.665: VERBOSE/Smacktest_01(4465): java.lang.Thread.run(Thread.java:1096)
03-01 15:13:39.705: VERBOSE/Smacktest_01(4465): creating chat
So the question is :) if I am doing something wrong, or the project is not prepared properly for the aSmack lib to be user on android?
There's the aSmack author's github https://github.com/rtreffer/asmack where he mentions that build environment, which is completely chinese for me. Shall I create a new build environment? How do I do that?
Thank you for your patience!
stream:error (text)
if you join a room twice, see: community.igniterealtime.org/thread/35991 – Christophe Roussy