This Question is Possibly Answered

1 "correct" answer available (10 pts) 1 "helpful" answer available (5 pts)
1 Replies Last post: Aug 28, 2007 8:56 PM by Chris Ward  
Bronze 8 posts since
Aug 28, 2007
Currently Being Moderated

Aug 28, 2007 10:50 AM

Packet Listener

 

Hello all,

 

 

I am trying to impl packet listener, such that when ever somebody tries to initate chat, I got the event for it.? Not sure PacketListener is the right choice. I can send the messages and initate chat myself, but I'm not getting event when somebody else tries to initate chat with me.I've code like this:

 

 

connection.addPacketListener(new MyPacketListener(), new OrFilter());

 

 

class MyPacketListener implements PacketListener {

 

 

    public void processPacket(Packet packet) {

        if (packet instanceof Message) {

            Message msg = (Message) packet;

            // Process message

            System.out.println("Subj: "msg.getSubject()", Body: "+msg.getBody()

             &n bsp;            &nbs p;    ", Type: "msg.getType());

        } else {

            System.out.println("=== Got a packet === "+packet);

        }

    }

}

 

 

 

 

Chris Ward Silver 100 posts since
Aug 16, 2005
Currently Being Moderated
Aug 28, 2007 8:56 PM in response to: Suhaib
Re: Packet Listener

Use the ChatManager to register a ChatManagerListener. This will notify you when a chat object is created either locally or remotely. Then, in that listener method attach a MessageListener to the newly created chat, which will get called whenever a new message arrives.

 

When a new chat is created you should cache it and then when you need to send a chat, try to use a cached one first, otherwise create a new one.

 

Hope this helps,

Chris

More Like This

  • Retrieving data ...