国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

REST Streaming

sarva / 3299人閱讀

1.Use REST streaming to connect products directly to nest services from cloud to cloud integrations.

2.In REST streaming, instead of returning information and close the connection, the NEST api keeps the connection open, and the REST api uses the open connection, and users can receive new state.

3.REST streaming allows for only one token(one user) per socket.

4.What is SSE(server-sent-events): a web app subscribes to a stream of updates generated by server, and whenever a new event occurs, it will send to the client.
AJAX:

       - Polling: the application repeatedly polls server for data.
       - Long Polling: the server does not have the data available, the server holds the data until new data is made available(Hanging GET). 

5.server-sent events are sent over http, but they do not require a special protocol or server implementation get working. When use server-sent requests, a server can push data to client whenever it wants, without making initial request, update can be streamed to clients as they happen. SSEs often use single un-directional channel between client and server.
Diff between SSE and Longpolling is: SSE is handled by browser and users have to listen for messages.

Server Sent Events vs Websockets:

websocket provides richer protocol to perform bi-directional, full-duplex communication, two way channel for games, messaging apps, and for cases when need real-time communications for both directions.

Server Sent Events: sometimes not needed to perform data sent from the client. Only need is to update the event from the server side.

//JavaScript API:
    if(!!window.eventSource) {   
        var source = new EventSource("stream.php");
    } else {
        //result to xhr polling;
    }
    //set up a handler for the message event
    source.addEventListener("message", function(e) {
        console.log(e.data);
    }, false);
    source.addEventListener("open", function(e) {
        //connection is opened
    }, false);
    source.addEventListener("error", function(e) {
        if(e.readyState == EventSource.CLOSED) {
           //connection is closed;
        }
    }, false);

Server implementation in NodeJS:

var http = require("http");
var sys = require("sys");
var fs = require("fs");

http.createServer(function(req, res) {
    if(req.headers.accept && req.headers.accept == "text/event-stream") {
        if(req.url == "/events") {
            sendSSE(req, res);
        } else {
            res.writeHead(200, {"Content-Type": "text/html"});
            res.write(fs.readFileSync(__dirname + "/sse-node/html"));
            res.end();
        }
    }).listen(8000);

function.sendSSE(req, res) {
    res.writeHead(200, {
        "Content-Type":"text/event-stream",
        "Cache-Control": "no-cache",
        "Connection": "keep-alive"
    });
    
    var id = (new Date()).toLocaleTimeString();
    
    //send a SSE every 5 seconds on a single connection
    setInterval(function() {
        constrcutSSE(res, id, (new Date()).toLocaleTimeString());
}

function constructSSE(res, id, data) {
    res.write("id: " + id + "
");
    res.write("data: " + data + "

");
}

function debugHeaders(req) {
    sys.put("URL: " + req.url);
    for(var key in req.headers) {
        sys.put(key + ": " + req.headers[key]);
    }
    sys.put("

");
}
    
        

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/108054.html

相關文章

  • Flink1.7穩(wěn)定版發(fā)布:新增功能為企業(yè)生產帶來哪些好處

    摘要:通過狀態(tài)演變,可以在狀態(tài)模式中添加或刪除列,以便更改應用程序部署后應捕獲的業(yè)務功能。本地恢復通過擴展的調度來完成本地恢復功能,以便在恢復時考慮先前的部署位置。此功能大大提高了恢復速度。問題導讀1.Flink1.7開始支持Scala哪個版本?2.Flink1.7狀態(tài)演變在實際生產中有什么好處?3.支持SQL/Table API中的富集連接可以做那些事情?4.Flink1.7新增了哪些連接器Ap...

    Hwg 評論0 收藏0

發(fā)表評論

0條評論

sarva

|高級講師

TA的文章

閱讀更多
最新活動
閱讀需要支付1元查看
<