[英]Faye Websocket in NodeJS
我是nodeJS和faye / websockets的新手。
使用webix制作了一個數據表,我想對其進行實時更新。
現在試圖通過Faye做到這一點,但不確定在Faye向我發送如下請求后應該怎么做:
[{"channel":"/meta/handshake","version":"1.0","supportedConnectionTypes":["websocket","eventsource","long-polling","cross-origin-long-polling","callback-polling"],"id":"1"}]
並得到回應:
[{"id":"1","channel":"/meta/handshake","successful":true,"version":"1.0","supportedConnectionTypes":["long-polling","cross-origin-long-polling","callback-polling","websocket","eventsource","in-process"],"clientId":"8bkeysctea7ucerz9h3tyjz0n52s5os","advice":{"reconnect":"retry","interval":0,"timeout":45000}}]
在服務器(NodeJS)上,我有以下代碼:
var http = require("http"),
faye = require("faye");
var server = http.createServer(function (request, response) {
//Here i have some code for the CRUD operations for the webix Datatable
}),
bayeux = new faye.NodeAdapter({ mount: '/faye', timeout: 45 });
bayeux.attach(server);
server.listen(1212, function () {
console.log("\r\n" + new Date() + "\n -->> HTTP Server listens to Port 1212 <<--\r\n ");
});
在客戶端(JS)上:
webix.proxy.faye.client = new Faye.Client("//localhost:1212/faye");
webix.proxy.faye.clientId = webix.uid(); // unique client id
webix.proxy.faye.client.connect();
HTML:
<script type="text/javascript" src="//localhost:1212/faye/client.js"></script>
(充分利用了webix示例和faye示例中的所有內容)
也許有人可以向我解釋下一步該怎么做,或者提供一個鏈接,使我可以閱讀有關Websockets以及如何使用它們的更多信息。
感謝您的時間。
在客戶端和服務器端配置faye后,可以將其用作任何組件的數據源
{
view: "datatable",
url: "faye->/data",
save: "faye->/data"
}
請注意,faye僅用於在客戶端之間同步數據,不會將數據加載或保存到真實數據庫中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.