diyabhat12 / asmack

Automatically exported from code.google.com/p/asmack
Other
0 stars 0 forks source link

Can only receive chats by polling #3

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I can't get the smack example code to work right.  Sending messages works 
fine, but processMessage() never fires when a message comes back.  But if I 
try the polling code from http://today.java.net/article/2006/10/04/instant-
messaging-java-made-easy-smack-api I can receive messages just fine.

That is, the code below only sends "testing". But if I uncomment the big 
block at the bottom, I receive messages as expected.

I'm running all this on an Android 2.1 AVD.

        // Sorry, I'm not good with Java.
        new Thread(new Runnable() {
          public void run() {            
            XMPPConnection xmpp = new XMPPConnection("jabber.iitsp.com");
            try {
              xmpp.connect();
              xmpp.login("actualusername","password");
            } catch (XMPPException e) {
              Log.v(TAG, "Failed to connect to " + xmpp.getHost());
              e.printStackTrace();
            }
            ChatManager chatmanager = xmpp.getChatManager();
            Chat newChat = chatmanager.createChat("foo@example.com", new 
MessageListener() {
              public void processMessage(Chat chat, Message message) {
                try {
                  Log.v(TAG, "Got:" + message.getBody());
                  chat.sendMessage(message.getBody());
                } catch (XMPPException e) {
                  Log.v(TAG, "Couldn't respond:" + e);
                }
                Log.v(TAG, message.toString());
              }
            });

            try {
              newChat.sendMessage("testing");
            } catch (XMPPException e) {
              Log.v(TAG, "couldn't send:" + e.toString());
            }

            // IF I UNCOMMENT THE FOLLOWING BLOCK, I CAN RECEIVE
            //  MESSAGES AS EXPECTED
            /*
            PacketFilter filter 
                = new AndFilter(new PacketTypeFilter(Message.class), 
                                new FromContainsFilter("foo@example.com"));

            PacketCollector collector = xmpp.createPacketCollector(filter);

            while(true) {
                Packet packet = collector.nextResult();

                if (packet instanceof Message) {
                    Message msg = (Message) packet;
                    Log.v(TAG, "Got message:" + msg.getBody());
                }
            }
            */
          }
        }).start();

Original issue reported on code.google.com by jh...@google.com on 2 Mar 2010 at 4:15

GoogleCodeExporter commented 8 years ago
Incidentally, I just figured out how to connect to google accounts:

Use XMPPConnection("gmail.com") and login("username@gmail.com", "password")

Original comment by jh...@google.com on 2 Mar 2010 at 4:33

GoogleCodeExporter commented 8 years ago
Could you add XMPPConnection.DEBUG=true; and Connection.DEBUG=true; before 
stating
the Thread? Can you provide a log of the messages send (minus the sasl part, of 
course).

What does "you can receive messages" mean? Can you receive messages in your 
loop and
in your chat manager or just in your loop?

TIA, René

Original comment by rtreffer@gmail.com on 2 Mar 2010 at 9:05

GoogleCodeExporter commented 8 years ago
I think I know this bug. You also need to listen for new Chats not only for 
Messages
in your existing chat since the ChatManager class in the original Smack has a 
bug
which creates for every incoming message a new Chat. This happens if the 
incoming
Message hasn't got a threadid or another threadid than the message you sent. 
Your
PacketCollector instead listens for all Messages it gets from the other JID no 
matter
what threadid they have. A PacketListener on the connection which listens for 
Message
packets should also work.

Original comment by till.klo...@gmail.com on 2 Mar 2010 at 12:30

GoogleCodeExporter commented 8 years ago
THX till, http://www.igniterealtime.org/issues/browse/SMACK-269 is what you 
mean,
right? Sounds like I should cherry-pick that one, too.

Any objectives?

Original comment by rtreffer@gmail.com on 2 Mar 2010 at 12:39

GoogleCodeExporter commented 8 years ago
Yeah, thats what I meant. At the moment I completely circumvent the ChatManager 
and
map the chats according to the jid. I'm completey ignoring the threadid since 
most
client don't set the threadid. This works pretty fine for me.

Original comment by till.klo...@gmail.com on 4 Mar 2010 at 12:03

GoogleCodeExporter commented 8 years ago
Ok, I'll have to read the spec, depending on that I'd
- clone the chat manager and provide a xmpp-thread-unsafe chat manager (if 
smack is
right)
- apply the patch (if smack is wrong)

Original comment by rtreffer@gmail.com on 5 Mar 2010 at 9:41

GoogleCodeExporter commented 8 years ago
http://xmpp.org/rfcs/rfc3921.html#rfc.section.2.1.2 looks like you're right. 
Clients
MAY send a thread-id for messages, but they aren't enforced to do so.

2.1.2.3 is even worse. Looks like messages should be grouped by 
jid,resource,thread
(with NULL being a correct value for grouping). Starting a thread with a thread 
id is
bad because we can't be sure if a reply (if any) will contain the thread id.

Google code and any RFC viewer should implement dislike button....

Original comment by rtreffer@gmail.com on 13 Mar 2010 at 2:38

GoogleCodeExporter commented 8 years ago
I see there's a new build of the code.  Has this issue been addressed in that 
build?  
Thx!

Original comment by tom.deck...@gmail.com on 6 Apr 2010 at 5:59

GoogleCodeExporter commented 8 years ago
Just confirmed it's fixed with asmack-2010.04.02.jar.  Thanks!

Original comment by tom.deck...@gmail.com on 8 Apr 2010 at 12:04

GoogleCodeExporter commented 8 years ago
Oh nice, didn't see the patch that fixed it, but glad to see your problem has 
been
addressed! Thanks for rechecking, and happy hacking!

Original comment by rtreffer@gmail.com on 8 Apr 2010 at 1:00