Skip navigation.

Listeners

The dojox.cometd API provides the MessageListener and RemoveListener interfaces to allow server side code to listen for message delivery or removal of a client.

Given an instance of the Client the following code demonstrates how listeners could be attached:


client.addListener(new RemoveListener(){
    public void removed(String clientId, boolean timeout){
        System.err.println("Client "+clientId+timeout?" timedout":" disconnected");
    }
});

client.addListener(new MessageListener(){
    public void deliver(Client fromClient, Client toClient, Message msg)
    {
        System.err.println("Client "+toClient.getId()+" received "+msg);
    }
});

Note that the client instance may be a reference to a remote client or may be a client created on the server. If the client instance is for a remote client, the MessageListener deliver method is called as the message is queued for delivery to the remote client.