Check out a free preview of the full Full Stack for Front-End Engineers, v2 course:
The "WebSockets" Lesson is part of the full, Full Stack for Front-End Engineers, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Jem explains what websockets are, the difference between them and long polling, and explains that websockets will be used in this course's final project.

Get Unlimited Access Now

Transcript from the "WebSockets" Lesson

[00:00:00]
>> Jem Young: The final projects. To do that we need to understand what a web socket is. What is a web socket? Yes.
>> Speaker 2: You can use it from the client to open a long-lived connection, and you just push messages back and forth, client to server. It's two way and multiplexed.

[00:00:20]
>> Jem Young: I don't know if you read the instruction, but that's exactly right. It's a persistent bidirectional connection between the client and server. So unlike the current status quo with TCP, which every single connection requires that handshake. With the handed off web socket, you only make one connection and it keeps that alive through a tunnel.

[00:00:38] So that way the client can send data, the server can send data, and it's much faster than a TCP connection, even though it runs over TCP. The moral of the story, is the web socket is this persistent connection that we can send streaming data. It's used a lot in chat applications things like that where you know for a fact the client is gonna keep communicating with the server.

[00:00:56] So why not just keep that connection open. What we used to do was this concept of long polling, which was open a TCP connection, and just keep it alive and just keep pushing data back and forth. And that way the client stays open, the server stays open. It's fine, but it's not as efficient as web sockets.