[JDEV] Client using JabberBeans..

Adrian Brown brown.adrian at btinternet.com
Mon Nov 25 17:41:57 CST 2002


If anyone is using JabberBeans, I would certainly appreciate you taking 
a look at this:

I'm trying to build a simple client, at the moment everything is quite 
static (until I get things right).

I can't seem to send the Message Packet to the other client (pre-set 
into code).. nothing seems to happen.  Is the code correct?

public class KeyEventAlgorithm extends Connection implements 
KeyListener, ActionListener {


     //Create a MessengerBean using the existing ConnectionBean within 
Connection Class
     //MessengerBean msgBean = new MessengerBean( cb );//Didn't work!

     //Thread test
     private String thread;
     { thread = Long.toHexString( ( new java.util.Random() ).nextLong() 
) ; }

     public KeyEventAlgorithm() {


     }

     //Listener method for KeyEventListener
     public void keyPressed( KeyEvent e ) {


     }

     //Listener method for KeyEventListener
     public void keyReleased( KeyEvent e ) {


     }

     //Listener method for KeyEventListener
     public void keyTyped( KeyEvent e ) {

         pushPacket( e );

     }

     //Listener method for ActionListener
     public void actionPerformed( ActionEvent e ) {

     }

     //Method to push <body> packet to other client
     protected void pushPacket( KeyEvent e ) {

         char c[] = { e.getKeyChar() };

         String s1 = new String ( c );

         System.out.println( s1 );

         //Create new Instance of MessageBuilder
         MessageBuilder msgBuild = new MessageBuilder();

         //Create new Instance of Message
         Message  message;

         msgBuild.reset();
         JID jid = new JID( "adrianxp", "jabber.org", "home" );
         JID jid1 = new JID( "adrian2000", "jabber.org", "work");

         msgBuild.setFromAddress( jid1 );
         msgBuild.setToAddress( jid );

         msgBuild.setThread( thread );
         msgBuild.setSubject( "Test client" );

         msgBuild.setType( "normal" );

         msgBuild.setBody( s1 );


         try {

             //Build Message Packet from MessageBuilder
             message = ( Message ) msgBuild.build();
             //Sends Message Packet
             cb.send( message );
         }

         catch( InstantiationException g ) {

             System.out.println( "Failed to build Message Packet");

         }
      }
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 4565 bytes
Desc: not available
URL: <https://www.jabber.org/jdev/attachments/20021125/e4ee47d0/attachment-0002.bin>


More information about the JDev mailing list