BreizhCamp 2016

#BzhCmp

image/svg+xml

Pourquoi ? Comment ?

WebSockets

Server-Sent Events

  • Push techno
  • W3C
  • 2008
  • Push techno
  • W3C
  • 2006

WebSockets

Server-Sent Events

WebSockets

Server-Sent Events

  • TCP
  • low-level protocol
  • HTTP upgrade handshake
GET /chat HTTP/1.1
Host: example.com:8000
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Version: 13
GET /stream HTTP/1.1 1
Host: example.com
Accept: text/event-stream

WebSockets

Server-Sent Events

proxies and load balancers reconfiguration

No need to reconfigure! 
(it's HTTP)

WebSockets

Server-Sent Events

WebSockets

Server-Sent Events

binary + text

native browsers support 

text

... but polyfills!

    Maximum browser connections per server/proxy

WebSockets

Server-Sent Events

3237 200 128 2970 900
6 6 8 6 6

HTTP

SSE

Beware of DOS!

WebSockets

Server-Sent Events

➟ use query params

WebSockets

Server-Sent Events

var websocket =
  new WebSocket('ws://mywebso/echo');
websocket.onopen = function () {
	...
};

websocket.onmessage = function (e) {
	...
};

websocket.onerror = function (error) {
	...
};
var eventSource =
  new EventSource('http://mysse/echo');
eventSource.onopen = function () {
	...
};

eventSource.onmessage = function (e) {
	...
};

eventSource.onerror = function (error) {
	...
};
source.addEventListener('foo', function(e) {
  ...
}, false);

   Web API

Some Java Servers

Some Clients

Use case: Préchargement de 500 Tweets sur une page web (nginx configuré en tant que proxy)

   "Perfs"

   Use Cases

WebSockets

Server-Sent Events

  • Fintech / Trading

  • Betting

  • Games

  • Realtime timetables

  • Animated data apps (charts, monitoring, etc.)

  • etc.

  • Chat, chat, chat (*)
  • Share living editing
  • GPS GoogleMap-like
  • Games

(*) WebRTC might be even more suitable

   Conclusion

Use the right tools for the right things.

Thank you!

   Merci !

Merci à Gregory Houllier pour l'utilisation du thème BreizhCamp avec revealjs

   Merci !

   References

Polyfills JS

   References

WebSockets / SSE

   References

Connection limits

Made with Slides.com