In the previous section, you learned how to listen to those built-in events—things such as connection events and disconnection events. Those are fine, and they're a great starting place, but in this section, what we want to talk about is emitting and listening to custom events, and this is where Socket.io gets really interesting.
When you're able to emit and listen to custom events, you can send anything you want from the server to the client or from the client to the server. Now, to go through a quick example of how that'll look, we're going to use an example app, which will be an email application:

On the left, we have our server, which is starting up a Socket.io web server. On the right, we have our email app, which is showing a list of all our current emails. Now, one custom event that our app might require is a newEmail event:

The newEmail event is going to be emitted by the server when an email comes in. For example, if I sign up to a new service, that service sends me an email to confirm my email. Then, the server eventually gets that email and it emits an event that the client listens to. The client is going to listen for the newEmail event and will be able to re-render the list of emails in the browser using jQuery, React, Ember, or whatever library it happens to be using, showing the new email to me, the user.
Now, aside from just sending a message that an event happened, the most important piece to the puzzle is sending data, and we can actually do that. When you create and emit a custom event, you can send whatever information you like from the server to the client or from the client to the server. Usually, this takes the form of an object with various properties. In the case of getting a new email, I might want to know who the email is from. I definitely need to know the text of the email, and I also want to know when the email arrived at my server so I can render what I need to inside the browser for whoever happens to be using the email app.
Now, this is data flowing from the server to the client, which is something we were not able to accomplish with HTTP requests, but it is something we can accomplish using Socket.io. Now, another event, the createEmail event, is going to flow from the client to the server:

When I create a new email inside my web browser, I'll need to emit that event from the client, and the server is going to listen for that event. Once again, we will be sending some data across. Although the data will be a little different, we want to know who the email needs to be sent to, we need the text of the email, and maybe we want to schedule it for down the line, so a scheduleTimestamp field could be used.
Obviously, these are all just example fields; your fields for a real email app would probably be a little different. With this in place, though, we are ready to go ahead and actually create these two events inside our application.