Building a chatting application with WebSockets

We now know how many browsers are connected. Suppose we want to build a chat room where users can type a message in their respective browsers and send the message to all the connected users instantly.

Sending a message to the server

We will let the user input a message and then send the message to the node.js server. The server will then forward the message to all the connected browsers. Once a browser receives the message, it displays it in the chat area. In this case, the users are connected to the instant chat room once they load the web page.

Get HTML5 Game Development by Example : Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.