Authors:Alex Russell, Greg Wilkins

Low-latency data transfer from servers to clients. dojox.cometd implements a Bayeux protocol client for use with most Bayeux servers. See for details on Cometd or on the Bayeux protocol.

Basic Example

Using dojox.cometd to connect to a Bayeux-compliant server is very straightforward:

As a simple example, we’ll setup a chat room; we will subscribe to a channel and log any messages received. When you send a message it is published on this channel. You can open a couple browsers to and send messages back and forth to see this in action. Just enter your name and type a message and click send.

dojo.require("dijit.form.TextBox"); // Those widgets are only included to make the example look nice
dojo.require("dijit.form.Button"); // Those widgets are only included to make the example look nice

    dojox.cometd.subscribe("/demo", function(message){
        console.log("received", message);
            appendChild(document.createTextNode( + ": " +;
    dojo.connect(dojo.byId("send"), "onclick", function(){
        if(!dojo.byId("sendName").value.length || !dojo.byId("sendText").value.length){
                            alert("Please enter some text");
                    dojox.cometd.publish("/demo", {
             from: dojo.byId("sendName").value,
             text: dojo.byId("sendText").value

The html is a just a simple form to enter you name and message to send

<div id="chatroom">
    <div style="clear: both;"><label for="sendName" style="float: left; width: 100px; padding: 3px;">Name:</label> <input id="sendName" type="text" data-dojo-type="dijit.form.TextBox"></div>
    <div style="clear: both;"><label for="sendText" style="float: left; width: 100px; padding: 3px;">Message:</label> <input id="sendText" type="text" data-dojo-type="dijit.form.TextBox"><button id="send" data-dojo-type="dijit.form.Button">Send Message</button></div>
    <div id="messageLog"><strong>Messages:</strong></div>
#messageLog {
  margin-top: 20px;
  padding: 5px;
  width: 400px;

Table of Contents

Error in the documentation? Can’t find what you are looking for? Let us know!