Book Image

CoffeeScript Application Development Cookbook

By : Mike Hatfield
Book Image

CoffeeScript Application Development Cookbook

By: Mike Hatfield

Overview of this book

Table of Contents (18 chapters)
CoffeeScript Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Communicating in real time with Socket.io


Socket.io is a node library that facilitates real-time two-way communication between the HTTP server and the web client. It has support for platforms, browsers, and devices.

In this section, we will see how to configure Socket.io with the express server and process messages between the client and server.

You can get more information on Socket.io from the project's home page at http://socket.io/.

Getting ready

We will be using an express server as our HTTP server configured to use the Jade view engine.

We begin by defining our application's node dependencies in a file named package.json:

{
  "name": "socket-demo",
  "description": "Socket.io Demo",
  "dependencies": {
    "express": "~3.4",
    "jade": "~0",
    "socket.io": "~0.9"
  }
}

Besides our express and Jade dependencies, we also take a dependency on the Socket.io node library.

Install the necessary packages by running the following command:

npm install

Now, let's create our app.coffee file to create...