Chapter 13. Interacting with servers using the WebSocket protocol
This chapter covers
- Implementing a server data push to Angular clients
- Broadcasting data from the server to multiple clients
- Splitting ngAuction into two projects
- Implementing bidding in ngAuction
WebSocket is a low-overhead binary protocol supported by all modern web browsers (see https://en.wikipedia.org/wiki/WebSocket). It allows bidirectional message-oriented streaming of text and binary data between browsers and web servers. In contrast to HTTP, WebSocket is not a request/response-based protocol, and both server apps and client apps can initiate data push to the other party as soon as the data becomes available, in real time. This makes the WebSocket protocol a good fit for the following types of applications:
- Live trading/auctions/sports notifications
- Controlling medical equipment over the web
- Chat applications
- Multiplayer online games
- Real-time updates in social streams
- Live charts
All of these apps have one thing in common: there’s a server (or a device) that may need to send an immediate notification to the user because some important event happened elsewhere. This is different from the use case when the user decides to send a request to the server for fresh data. For example, if a stock trade happens on the stock exchange, the notification has to be immediately sent to all users.