TransJam Collaboration Server

TransJam Client Programming Tutorial

Home Documentation Chat Demo WebDrum

Using a ClientAdapter to Receive Messages

Messages are sent to the client from the server. The messages may be text messages from another client. Or they could be administrative messages from the server. Messages are exchanged when logging in, changing rooms, manipulating "things" on the server, etc.

A client can use a ClientAdapter which receives all of the messages that can be sent. If you would like to handle specific messages, then you can redefine the method that receives that method. This is similar to the WindowAdapter class in the AWT.

For example, here is a subclass of ClientAdapter that receives messages sent from other clients. The message contains the value of a Scrollbar in text format. The value is parsed and then printed.

    ClientAdapter clientAdapter = new ClientAdapter()
    // This message was sent to everyone in the room including the sender.
    // For this Applet, it contains the value of the senders Scrollbar in text format.
        public void sentAll( int uid, String text ) throws IOException
            int value = Integer.parseInt( text );
            System.out.println("User " + uid + " sent value = " + value );
Here we ask that our ClientAdapter be called when messages arrive from the server. By specifying Client.APPLICATION_LEVEL we can request that we only get messages when in a room specific to the application. We will not be  sent messages that involve logging in or choosing a room.
    client.addMessageListener( clientAdapter, Client.APPLICATION_LEVEL );

[Previous] [Top] [Next]

(C) 2002