From the course: Node.js: Web Servers, Tests, and Deployment

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Emitting Socket.IO events

Emitting Socket.IO events

- [Instructor] Another benefit of using Socket.IO is its ability to raise events by name. The Web Socket Spec only handles message events so that means that all types of data has to be served through the same event. It would take us a lot of code to separate different chat environments and push many different types of data using only one event. So let's handle these different events. So in the previous lesson we created the emit event where we're passing in the name of the event called message. So the way that I can deal with this on the client is I can say socket.on message. We'll take in the message and the id and we'll console.log the id and the message. Next, we want to say process.stdin.on. So anytime we get some new data, in other words any time I collect information from the terminal from our user, we want to take that data and we want to call socket.emit. We want to admit the chat event and use…

Contents