promotion image of download ymail app
Promoted
LCH 發問時間: 社會與文化語言 · 6 年前

尋求翻譯<伺服器推播的>

Related articles: Bringing realtime to your web applications and WebSockets vs Server-Sent Events vs Long-polling

Besides, already noted bidirectional communication channel, known as WebSocket, HTML5 propositions include also comet communication pattern by defining Server-Sent Events (SSE). WebSocket widely discussed by now, tons of server implementations are available and you can play already with fluent browser implementation under Chrome. However the second server-push technology of HTML5 yet stays in shadow.

We are used to consider the HTTP protocol as request-response model, which means that the client sends a HTTP request and waits until the HTTP response is received. So, normally the server cannot communicate to client unless it’s requested. Even to have such a trivial thing as user online status we are obliged to go with workarounds. You know, it’s called COMET and whatever approach you choose it’s still a hack. HTML5 is designed to change it. It provides a native way to handle server-sent events. HTML 5 defines an API for opening an HTTP connection for receiving push notifications from a server. Just check it out how easy to use the interface is:

The server-side scripts keeps sending messages in following form (text/event-stream MIME type):

Moreover, you don’t need to apply a loop-cycle in the event source script. That will seem as repeat of pushing messages to the client automatically.

How does it work? The client opens an event stream by creating an EventSource, which takes an event source URL as parameter. The onmessage event handler will be called each time new data of event source comes. You see, having AJAX, we can asynchronously communicate from the client to the server and, now using SSE we can do it in opposite direction from the server to the client, again asynchronously.

WebWorkers is other nice technology of HTML5. This one allows running scripts in the background independently. So you can handle the per-server connection lim

1 個解答

評分
  • 6 年前
    最佳解答

    Related articles: Bringing realtime to your web applications andWebSockets vs Server-Sent Events vs Long-polling相關文章: 將即時串流帶進你的web應用以及WebSockets vs Server-Sent Events vs Long-pollingBesides, already noted bidirectional communication channel, known asWebSocket, HTML5 propositions include also comet communication pattern bydefining Server-Sent Events (SSE).除了已經引起大家注意的並廣為人知的雙向通訊頻道WebSocket,HTML5中準備藉著新的Server-SentEvents (SSE)協定加入comet communication(慧星通訊)的功能。 WebSocket widely discussed by now, tons of server implementationsare available and you can play ....WebSocket現已被廣泛的討論,許多伺服器已經可以支援,而且你也可以在Chrome底下流暢的播放。無論如何,在HTML5中的第二代推播技術還沒有完全成熟。We are used to consider the HTTP protocol as request-response model,which means that the client sends ....我們常把HTTP協定當成是要求-回應架構的標準模型,也就是說當client端送出HTTP請求並等待接收伺服端的回應。因此,正常來說,伺服端並不能主動的要求與client端溝通。 Even to have such atrivial thing as user online status we are obliged to go with workarounds. You know,....即使是像使用者有沒有在線上這種小事,我們都必須要花一番工夫才能得知。對,這種技術就是COMET,而且不論你用甚麼方法都不是甚麼正規的伎倆。HTML5的出現就是為了改變這種現況。 It provides a native way to handle server-sent events. HTML 5defines an API for opening ..它提供了原生的方式去處理伺服端推播的事件。HTML5定義了標準的API,用來建立一個HTTP連線,可以接收從server端推播的通知。 Just check it out howeasy to use the interface is:讓我們來看看這個介面會有多方便:The server-side scripts keeps sending messages in follo.....伺服端持續用(text/event-stream MIME type)送訊息出去:Moreover, you don’t need to apply a loop-cycle in the event sourcescript. That will seem as repeat of pushing messages to the clientautomatically.而且你也不需要去管訊息的週期,自然而然就會送到client端面前。How does it work? The client opens an even.....這是怎麼做到的? Client端需要使用EventSource打開一個事件串流,EventSource裡需要包含URL位置作為預設參數。The onmessage event handler will be called each time new data of eventsource comes. You see, having AJAX, w...onMessage 訊息處理器將會處理接下來的事件。看到沒,有了AJAX,cilent到server端可以達成非同步的溝通,現在使用了SSE,我們也可以反向的從Server到client端非同步溝通。WebWorkers is other nice technology of HTML5. ...WebWorkers 是HTML裡另一項好用的技術。他允許了網頁背景執行某些獨立的事項。所以在連上伺服端前就可以做好準備

    • Commenter avatar登入以對解答發表意見
還有問題?馬上發問,尋求解答。