我想推送消息從服務器到客戶端。我正在使用DOJO 1.7,Cometd和Jetty與tomcat6集成。服務器推送使用COMETD客戶端(dojo)
//Server side code
public class notificationService extends AbstractService {
public notificationService(BayeuxServer bayeux, String name) {
super(bayeux, name);
System.out.println("Inside constrcutor of Notification Service");
addService("/notification", "processNotification");
}
public void processNotification(ServerSession remote,ServerMessage.Mutable message)
{
System.out.println("Inside process Notification");
Map<String,Object> response = new HashMap<String,Object>();
response.put("payload",new java.util.Date());
getBayeux().createIfAbsent("/notification");
getBayeux().getChannel("/notification").publish(getServerSession(),response,null);
//remote.deliver(getServerSession(),"/notification", response, null);
}
//Client Side Code (DOJO)
var cometd = dojox.cometd;
cometd.init("http://serverip:port/cometd")
cometd.publish('/notification',{ mydata: { foo: 'bar' } });
cometd.subscribe('/notification', function(message)
{
//alert("Message received" + message.data.payload);
//alert(message.data.payload);
alert("Message received");
});
我想廣播消息給所有的客戶訂閱特定的頻道。當m使用remore.deliver時,它將消息發送給單個客戶端,但不發送給訂閱該頻道的所有客戶端。 channel.publish不適合我...任何幫助和意見,高度讚賞。