Using JSON with Socket.IO
Setting up the Socket.IO
server is simple. Here is the procedure to implement a real-time server that provides a continuous HTTP handshake, and continues to listen to requests via the Socket.IO framework.
We are going to demonstrate the implementation of JSON for real-time via a pinboard app. Any anonymous user who connects to the real-time server joins the session, and can view the pinboard and add whatever thoughts or whatever else that they like.
We are going to divide our application into two phases :
- Designing the board
- Implementing the real-time functionality via the
Socket.IO
library
Designing the board
In this phase, we are going to design a web interface through which our user can add or view the pins on the board. Remember how in Chapter 7, Alternate Implementations of JSON, we learned about template embedding? We are going to use a similar technique for our pinboard. So, let's start by creating a template file called index.html.js
and inserting the following...