Not receiving message packets from google talk directly

I am observing curious behaviour trying to send messages via a connection to google talk. I have an unfiltered packet listener on the connection, but messages sent by the gtalk user do not get passed to it. However, I do see them in the debugger. The same code, connected to the google talk user by connecting via jabber.org, does receive the messages. I am able to send messages to the google talk user.

The message coming directly from the google talk user looks like this:

As you can see, the main difference is in the resource on the To field. Smack, on the google connection, is stripping part of the resource and adding in a random string. However, the resource is the right one, so I don’'t know why the message is not being delivered to my packet listener.

Hmm. No answer. So let me ask, is anybody receiving successful initiation of messages from a google talk account while logged in to talk.google.com using the GoogleTalkConnection class in smack?

ie. you create new GoogleTalkConnection(), you login() with a resource, and you addPacketListener( listener, null ) and wait for packets to arrive at a listener. If you have done this, can I see the code, so as to figure out what’'s wrong with mine? Anybody know why this class modifies the resource with a random string, does google insist on that?

Hey,

From what I remember I’‘ve had no problems receiving messages from a GoogleTalk account. I’'m not sure I used the GoogleTalkConnection though.

I’'m at work all day but will check the code when I return home tonight.

Jon

I’‘ve had a quick look, and in it simplest form this is what I’'ve come up with that works

String username = “johnsmith”;

String password = “password”;

String resource = “work”;

GoogleTalkConnection googleConnection;

try {

googleConnection = new GoogleTalkConnection();

PacketTypeFilter filter = new PacketTypeFilter (Message.class);

googleConnection.addPacketListener(new GooglePacketListener(), filter);

googleConnection.login(username, password, resource);

while(true) {}

}

catch(XMPPException e) {}

/code

now the PacketListener

public class GooglePacketListener implements PacketListener {

public void processPacket(Packet packet) {

Message message = (Message)packet;

Message.Type type = message.getType();

if(type == Message.Type.CHAT) {

System.out.println("Message From: " + message.getFrom());

System.out.println("Message: " + message.getBody());

}

}

}

/code

I’'ve run this against Pandion. Pandion sees the logged in GTalk user and on sending them a message it appears in the cmd window.

You should be able to just copy and paste this code, change the login details and it will work. Let me know if you get stuck further.

Jon

Thanks, I now see the problem and it was a stupid one. Since my first attempts to contact google using the regular xmppconnection constructor were failing, I did a quick method override to make a subclass just for google connecting, using the custom google connector class, and in doing so made a silly difference between the classes that stopped the packetlistener from getting added. Dumb.

Though now, I will point out, it has created another strange bug I’'ve been getting when talking directly to google, namely that my IMs to it get reflected back rather than being redirected. I will plug away at that a bit more.

So further notes, just so people can find them here. My other problem was due to some finer points of xmpp.

I had written a “reply” method that created a new message using the old from and to headers from the incoming message. On a new message from gtalk, the “to” was just "user@gmail.com" with no resource field. However, I was putting that into the from – actually not necessary because an empty from will be filled in by the server it seems – and this was causing an error from the google talk server. It didn’'t like a message that was from a user name with no resource.

(The error coming back was what I thought at first was the reflection of the message. I was not handling errors properly.)

Anyway, jabber.org, on the other hand, accepted the message with a “From” with no resource, and relayed to google talk which was able to handle it.