HTML and CSS Reference
In-Depth Information
4.1.2. When to use SSE
Before we move on to WebSockets, let's step back to consider why it was worth bothering
with SSE. After all, server-sent events do have some obvious disadvantages:
• You can only communicate from the server to the client.
• SSE offers little advantage over long-polling or forever frame.
If your application implemented one of the older hacks, it would probably not be worth
updating just to take advantage of an event-driven interface consistent with other HTML5
APIs. SSE won't dramatically lower the communication overhead compared to these
hacks. If you're starting from scratch, SSE does have advantages over WebSockets (which
we'll talk about in the next section):
• It's an extremely simple wire protocol.
• It's easy to implement on cheap hosting.
If you're working on a hobby project, SSE will probably be a good fit for you. But if you're
working on high-load, web-scale startups where you're constantly tweaking the infrastruc-
ture, you'll want to look closely at WebSockets, the pièce de résistance of the HTML5
communication protocols.
In the next section you'll use Node.js web server (also commonly referred to as just plain
Node ) to write an application using WebSockets. Node is well suited to SSE and WebSock-
ets because it's designed from the ground up to do event-driven communication (frequent,
small, but irregular message sending; see appendix D ) . If you're used to web servers like
Apache or IIS, it works differently than you might expect. It's therefore worth spending
time becoming familiar with the basics.
4.2. Using WebSockets to build a real-time messaging web app
WebSockets allow bare-bones networking between clients and servers with far less over-
head than the previously more common approach of tunneling other protocols through
HTTP. With WebSockets it's possible to package your data using the appropriate protocol,
XMPP (Extensible Messaging and Presence Protocol) for chat, for example, while also be-
nefiting from the strengths of HTTP.
 
Search WWH ::




Custom Search