Advanced CommunicationLesson 73Free preview
WebSockets
This lesson is part of Node.js · All levels
Summary
This lesson explains WebSocket, a two-way communication protocol over a single TCP connection that remains open. You'll understand the difference with HTTP polls and see how to create WebSocket servers in Node.js with libraries like ws. WebSocket became the foundation of real-time features like notifications, collaborations, and live dashboards.
Key points
- WebSocket opens the connection once and then two-way communication takes place during the live connection.
- Handshake starts with an HTTP upgrade.
- The HTTP server is typically request-response; WebSocket is bidirectional.
- The 'ws' library provides WebSocket.Server and event open/message/close.
- Once connected, sending messages is much safer than repeated HTTP requests.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.