Lesson 30. Working with Socket.Io

 

Building a web application in Node.js can be exciting. Often, you’ll find that the most challenging aspects stem primarily from architecting the application from a web-development perspective. It’s easy to forget what Node.js is capable of outside the normal request-response cycle. In this lesson, you explore communication between the client and server via an open TCP connection. This connection is made available by means of the socket.io package, which runs on web sockets and long polling, using normal HTTP requests held for longer periods on the server before responses are returned to facilitate a live-stream of data between client and server. You start by learning how to implement socket.io with Express.js. Then you create a chat box in a new application view. Last, you connect the client-side JavaScript and server code through custom events triggered and handled by socket.io.

This lesson covers

  • Implementing socket.io in a Node.js application
  • Structuring your socket.io listeners within a controller
  • Creating a simple chat feature

30.1. Using socket.io

30.2. Creating a chat box

30.3. Connecting the server and client

Summary