O'Reilly logo

Node Web Development - Second Edition by David Herron

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sending messages between users

Let's try something a little more complex, and closer to the intended purpose of Socket.IO. Let's implement a way for Notes' users to send each other messages within Notes.

When a user logs in, and they have messages, we'll show those messages in a box at the top of the screen. We'll also allow the user to delete those messages, and of course to send messages to themselves or other users.

Let's get started.

Socket.IO events for sending messages between users

The events we'll be sending and receiving are:

  • newmessage: This event indicates that a message has been created. It includes the user ID of the recipient of the message. It's sent from the server, and the code in the browser is to retrieve the current list of messages. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required