dojo.io.bind for tomcat 6 comet
Here is a basic example what I did, using dojo.io.cometd, and Jetty
Continuations within Tomcat 5.5. OOTB "long-polling" transport was
selected by default, also note I have some additional connects to
functions for tracking lifecycle of connection but those are not
strictly required. Also note that using the Jetty module requires
additional configuration via. web.xml. As long as it's cometd / Bayeux
protocol, this client side code should work with Tomcat 6 AFAIK:
1) Setup the connection when the page loads
dojo.require("dojo.io.cometd");
function setUpConnection(){
dojo.event.connect(cometd,"finishInit",function(type, data, evt,
request){
//alert("Finished Initializing.." + request);
transportObject = request;
//
// subscribe once connection is finished initializing
//
cometd.subscribe("/events/received", true, "serverSentEvent");
// was +cometd.clientId;
});
dojo.event.connect(cometd,"tunnelInit",function(type, data, evt,
request){
alert("TunnelInit...");
});
cometd.init({}, "/appcontextpath/cometd"); // replace appcontextpath
with your applications context path
// cometd.subscribe("/events/received", true, "serverSentEvent");
// set connected state for page
// this should possibly only be set on callback notification
connected = true;
}
2) serverSentEvent is the callback function for when a message is
received. In my case I take the callback and publish it's contents to a
topic locally in the browser, using dojo.event.topic, but that's not
require.
3) publish a message to "/events/received", for testing you can setup a
JS function on the same page for testing
function testDOJOEvent(){
cometd.publish("/events/received", {
source: cometd.clientId
});
}
Here I'm just pinging, with no message sent. I also have a Java client
that posts messages on the same channel from the server side (i.e. to
send events to the browser), via org.mortbay.cometd.Channel.publish(). I
believe there is also a chat example floating around on the net that
should be applicable as well.
HTH,
Mike
Dojo Forum
Comments
Here is a basic example what I did, using dojo.io.cometd, and Jetty
Continuations within Tomcat 5.5. OOTB "long-polling" transport was
selected by default, also note I have some additional connects to
functions for tracking lifecycle of connection but those are not
strictly required. Also note that using the Jetty module requires
additional configuration via. web.xml. As long as it's cometd / Bayeux
protocol, this client side code should work with Tomcat 6 AFAIK:
1) Setup the connection when the page loads
dojo.require("dojo.io.cometd");
function setUpConnection(){
dojo.event.connect(cometd,"finishInit",function(type, data, evt,
request){
//alert("Finished Initializing.." + request);
transportObject = request;
//
// subscribe once connection is finished initializing
//
cometd.subscribe("/events/received", true, "serverSentEvent");
// was +cometd.clientId;
});
dojo.event.connect(cometd,"tunnelInit",function(type, data, evt,
request){
alert("TunnelInit...");
});
cometd.init({}, "/appcontextpath/cometd"); // replace appcontextpath
with your applications context path
// cometd.subscribe("/events/received", true, "serverSentEvent");
// set connected state for page
// this should possibly only be set on callback notification
connected = true;
}
2) serverSentEvent is the callback function for when a message is
received. In my case I take the callback and publish it's contents to a
topic locally in the browser, using dojo.event.topic, but that's not
require.
3) publish a message to "/events/received", for testing you can setup a
JS function on the same page for testing
function testDOJOEvent(){
cometd.publish("/events/received", {
source: cometd.clientId
});
}
Here I'm just pinging, with no message sent. I also have a Java client
that posts messages on the same channel from the server side (i.e. to
send events to the browser), via org.mortbay.cometd.Channel.publish(). I
believe there is also a chat example floating around on the net that
should be applicable as well.
HTH,
Mike