From the course: Learning Node.js

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Connect to Socket.io from the browser app

Connect to Socket.io from the browser app - Node.js Tutorial

From the course: Learning Node.js

Start my 1-month free trial

Connect to Socket.io from the browser app

- [Instructor] We are able to send requests from the client or browser to Node, but there is no way to do it in reverse. There's no way for Node to tell one or more clients, hey, there's a new message, so the only way to achieve this behavior with HTTP requests is to do something called polling. With polling, every few seconds we send an HTTP request asking the server, hey, are there any updates? Are there new messages I should display? And we check over and over. It would be much better if the server could just tell the client when a new message comes in without the clients having to constantly check. You can think of it as a bunch of kids in a van asking the parents every minute, hey, are we there yet? The parents might plead with the kids to stop asking at one point, and that they will tell the kids when they arrive instead of them asking. This is how WebSockets work and we will be using a WebSocket library called Socket.IO that works for both the browser and for Node. With…

Contents