12. Server Sent Events
12
Server
The event stream is a simple stream of text data,
which must be encoded using UTF-8. Each
message is separated by a pair of newline
characters.
https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events#Event_stream_format
13. Event Stream Example
https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events#Event_stream_format
13
17. Which one is better?
17
• Server-Sent Events
• Are sent over traditional HTTP
• Automatic reconnection
• Ability to send arbitrary events
• WebSockets
• Bi-directional, full-duplex communication
18. Chatroom Example
• Polling approach:
• http://chichia.aws.prd.demodesu.com:5002/type/polling
• Long Polling approach:
• http://chichia.aws.prd.demodesu.com:5002/type/lpolling
• Server Sent Event approach:
• http://chichia.aws.prd.demodesu.com:5002/type/sse
• Websocket approach:
• http://chichia.aws.prd.demodesu.com:5002/type/ws
18
20. References
• Long Polling
• Jonathan Eunice lpoll
• AlanYang gevent-flask-comet
• Websocket
• Jonathan Eunice flask-ws-example
• Server Sent Event
• Oskar Blom Realtime Server Using The SSE Protocol
• Eric Bidelman Stream Updates with Server-Sent Events
• MDN Using Server Sent Event