powered by Jive Software

Packet/MessageListener not working?

(Using Smack for Google Talk)

I can’‘t get my PacketListener to pick anything up when I call addMessageListener on my chat variable.I really don’‘t understand it. I’‘ve implemented PacketListener, created a processPacket(Packet packet) method, I’‘ve connected to the user I want to chat with, I’‘ve called Chat.setFilteredOnThreadID(false);, I’‘ve added the message listener to my chat… and the debugging println statement I put into the processPacket method isn’'t even reached!

Here’'s my code (with irrelevant parts omitted for space):

import …;

public class GoogleMUCC extends Frame implements …PacketListener


// Jivesoftware

private GoogleTalkConnection connection;

private Chat hub;

public void processPacket(Packet packet)



String sender = packet.getFrom();

Message incoming = hub.nextMessage();

String line = incoming.getBody();



public void itemStateChanged(ItemEvent e)…

public void actionPerformed(ActionEvent e)


if((fired == sendMessage || fired == send) &&

!sendMessage.getText().equals("") && loggedIn)


message = sendMessage.getText();





}// get actions that have been fired

private void log(String message,String sender)




log = timestamp() + " <" + sender + "> " + message + “\n” + log;




log += “\n” + timestamp() + " <" + sender + "> " + message;



private void sendToHub(String message)






catch(XMPPException xmppe)


System.err.println("#-# Could not send message to MUC hub");






private boolean disconnect()…

private boolean connect(String name, String psw)




connection = new GoogleTalkConnection();



catch(XMPPException xmppe)


System.err.println("#-# Could not login");

return false;


      hub = connection.createChat("gtalkmuc@gmail.com");




return true;

}// Connect to talk.google.com

private void setupDialog(boolean in)…

private void setTitle()…

private void login(boolean in)…

private String timestamp()…

private void addComponents()…

private void addListenersToComponents()…

private void setBoundsOfComponents()…

public GoogleMUCC()…

public static void main(String[] args)…

public void windowActivated(WindowEvent e){}

public void windowClosed(WindowEvent e){}

public void windowClosing(WindowEvent e){System.exit(0);}// close program

public void windowDeactivated(WindowEvent e){}

public void windowDeiconified(WindowEvent e){}

public void windowIconified(WindowEvent e){}

public void windowOpened(WindowEvent e){}


It all creates a GUI window, I’'m designing a GoogleTalk client that only talks to one user - a bot (gtalkmuc@gmail.com) that will act as a Multi-User Chat hub. For anyone talking to gtalkmuc from Google Talk, thier messages to it will be sent to anyone else talking to gtalkmuc, and gtalkmuc will say something along the lines of: “jorgie: how are you”

for anyone using the client, however, responses from gtalkmuc will be parsed such that it seems to be an actual MUC, and the client will tell gtalkmuc when connecting that this is coming from my client, and gtalkmuc will send all users it is talking with.

that is the plan. nothing for gtalkmuc has be written yet, but trying to send messages while logged into gtalkmuc and my client produces nothing. the processPacket method is never reached.

however, I can send messages from the client to gtalkmuc just fine

you need to call Chat.setFilteredOnThreadID(false) /code before you create the chat as the PacketFilter is created in the Chat constructor.