This course has been updated! We now recommend you take the Complete Intro to Real-Time course.

Check out a free preview of the full Real-Time Web with Node.js course:
The "Socket.io Wrap-up" Lesson is part of the full, Real-Time Web with Node.js course featured in this preview video. Here's what you'd learn in this lesson:

Kyle concludes his Socket.io coverage with a few audience questions and additional discussion.

Get Unlimited Access Now

Transcript from the "Socket.io Wrap-up" Lesson

[00:00:00]
>> [MUSIC]

[00:00:04]
>> Kyle Simpson: That might feel a little bit creepy that you could spy on things but just know, that's already possible because WebSocket have better technology that's been around forever. [COUGH] So it's quite possible that you're already doing that and some of you may know that there are [COUGH] software packages out there that track mouse movements so they can tell marketers where people are moving their mouse on the page or things like that.

[00:00:27] So we're just taking advantage of that to create a simple little demo but it points out the fact that there's really not much of a limit to the sorts of things that we can send along in our WebSocket connections even somebody's mouse movements. [COUGH] Now I wouldn't necessarily say that just because we have a web socket connection established, we should send all communications through it.

[00:00:48] You could think about the downsides that can occur when you send large amounts of data over the web socket connection because really what you're wanting is the lowest latency possible for your real time communications. If you're also doing file uploads of giant pictures and you're doing that over web sockets, there's a pretty good chance that the other stuff that you want to be really fast is gonna be slowed down by all that giant picture sending stuff.

[00:01:15] So I'd recommend that you use WebSockets for tiny little event messages like the sorts of things we've been talking about. And you reserve normal Ajax, inform post sorts of communication for your large communications like file uploads, file downloads things like that. But it is possible you can send binary data over a WebSocket if you needed to.

[00:01:36] So that is possible.
>> Speaker 2: Let's say, like this here database.
>> Kyle Simpson: If you were going to make an Ajax request that wanted to load up you know one hundred records. That's a pretty substantial amount of data and I probably wouldn't do that over a WebSocket. But on the other hand, if you had like a data binding thing where you were updating one record on the server and you wanted to send that one record out to the client really, really fast.

[00:02:03] You could send one records worth of data over that WebSocket without too much of a problem.
>> Kyle Simpson: All right, any more questions about WebSocketr how we've worked with node?
>> Speaker 3: So WebSocket would be more appropriate for if you wanted to do multiplayer games?
>> Kyle Simpson: Yeah. The most common use cases are games, real time chats, collaboration apps like when you're drawing something and showing other people or typing something and other people seeing what you're typing.

[00:02:40] Real time stock feeds things like that. So anything where you have small bits of data that needs to be transmitted as quickly as possible. That's really kind of the sweet spot for WebSocket. And as we said we've made a massive leap in terms of you an order of magnitude reduction in terms of latency over the typical AJAX request and response lifecycle.

[00:03:02] So we've gotten to the point where it's practical that you can actually have a mouse moving in near real time.