我正在尝试开发一个 Faye 服务器端客户端以根据需要自动运行。在Faye的官方网站上,我只找到了关于服务器端客户端的文档,没有关于如何运行它的信息。
请告诉我该怎么做
谢谢
文档中缺少一个关键部分。看来你需要打电话client.connect()
为了接收事件。
这对我有用:
var faye = require('faye');
var client = new faye.Client('http://localhost:8000/faye');
//This was missing from the documentation
client.connect();
var subscription = client.subscribe('/foo', function(message){
console.log("Event Received");
console.log(message);
})
//This is optional
subscription.then(function() {
console.log('Subscription is now active!');
});
var publication = client.publish('/foo', {text: "Hello World!"});
publication.then(function() {
console.log('Message received by server!');
}, function(error) {
console.log('There was a problem: ' + error.message);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)