From the course: Node.js: Real-Time Web with Socket.IO

Unlock the full course today

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

Events: Connect and disconnect

Events: Connect and disconnect

From the course: Node.js: Real-Time Web with Socket.IO

Start my 1-month free trial

Events: Connect and disconnect

- [Instructor] There are a dozen events in the socket APIs, and we'll explore a few as we code new elements within the application. Let's explore the connect and disconnect server in client events. So what I want you to do first is go inside of the index.html, so the client; and just above the socket.on, add a new line. And on this new line, we'll add the socket.on and the event. And by the way, the events that I'm mentioning on this video are reserved by the APIs, the Socket.IO APIs. So basically you cannot use them for your own events, and basically if you want to take a look at more details around each of these APIs, you can take a look at the documentation. But they're fairly simple, and they'll explain how to use them; this one is fairly simple. It's basically like the other ones that we've done so far. So, for example, on connection, on the client, emit to everybody; and we'll use the message event, and we'll just say user connected. And that'll start to make you understand the…

Contents