16 Real-Time Communication with WebSockets
With regular GET
and POST
requests, your browser has to make a new
request and wait for a response for each exchange of data with the
server. As you learned in earlier chapters, this is also the case
with Ajax requests. While Ajax requests do not cause page reloads,
they do generate just as much network traffic, with each request and
response requiring a little bit of overhead to produce and process.
WebSockets, on the other hand, provides a two-way communication protocol over HTTP. It creates a single connection and keeps it open for real-time communication (Figure 16.1).
Figure 16.1 Multiple Ajax requests vs a single WebSockets connection
With WebSockets, web applications ...
Get Front-End Web Development: The Big Nerd Ranch Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.