{"symbol": "APPL", "id": 555, "price": "451.29"}
Demo
Demo
Every data push had:
{"symbol": "APPL", "id": 555, "price": "451.29"}
Reducing kilobytes of data to 2 bytes… and reducing latency from 150ms to 50 ms is far more than marginal. In fact, these two factors alone are enough to make WebSocket seriously interesting…
www.ietf.org/mail-archive/web/hybi/current/msg00784.html
Ian Hickson (Google)
window.WebSocket
object. No plugin required
Handshake
Here is sequence of the steps of initial handshake
UPGRADE
HTTP-request
UPGRADE
UPGRADE
response
readyState
property of WebSocket object to open
var ws;
if (window.WebSocket) {
console.log("WebSocket supported in your browser");
ws = new WebSocket("ws://echo.websocket.org");
// Set event handlers.
ws.onopen = function () {
console.log("onopen");
};
ws.onmessage = function (e) {
// e.data contains received string.
console.log("echo from server : " + e.data);
};
ws.onclose = function () {
console.log("onclose");
};
ws.onerror = function () {
console.log("onerror");
};
}
else {console.log("WebSocket not supported in your browser");}
if (ws.readyState === 1){ ws.send("Hello WebSocket!"); }
What are SSE?
Demo
Polling
Long Polling
Streaming
Demo
WebSocket: Known Facts
tl; dr Note sure about proxies - use TLS/SSL
Clients:
Server:
vert.x to rule them all:
We use NGINX as:
Recently NGINX team added WebSockets protocol support
WebSockets really shine with following applications: