我正在尝试开发 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);
});
关于node.js - Faye 和 nodejs : How to run Faye server side client?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6055237/