[JDEV] jabberbeans example

Jason Anderson jason at guanosoft.org
Thu May 30 12:57:33 CDT 2002


Duncan,

You need to register a listener on the connection, either by this:

class MyPacketListener extends PacketAdapter { ... }
connectionBean = new ConnectionBean();
connectionBean.addPacketListener(new MyPacketListener());

or by this:

class MyPacketListener extends PacketAdapter { ... }
connectionBean = new ConnectionBean();
messengerBean = new MessengerBean(connectionBean);
messengerBean.addPacketListener(new MyPacketListener());

and then MyPacketListener should look something like this:

class MyPacketListener extends PacketAdapter {

     public void receivedPacket(PacketEvent pe) {
         Packet p = pe.getPacket();

         // This if is not needed if you use MessengerBean
         if (p instanceof Message) {
             Message m = (Message)p;

             // normal, chat, or headline
             System.out.println("Message of type: " + m.getType());
             System.out.println("\treceived from: " + 
m.getFromAddress().toString());
             System.out.println("\tbody: " + m.getBody());
         }
     }

}

Of course, you need to connect the connection bean before this will do 
anything.  I hope this makes sense.  It won't compile like this, mind 
you. ;)

jason

Duncan Hoyle wrote:
> Hi
> 
> Does anyone have any example code for a message handling
> loop (ie. just sits there and processes incoming messages
> from the server) using jabberbeans? The examples directory
> isn't very complete and the documentation isn't very clear.
> I've managed to get an example which logs on and sends a
> single message but that's all.
> 
> Thanks
> 
> Duncan
> _______________________________________________
> jdev mailing list
> jdev at jabber.org
> http://mailman.jabber.org/listinfo/jdev
> 
> .
> 





More information about the JDev mailing list