Book Image

Websocket Essentials: Building apps with HTML5 websockets

By : Varun Chopra
Book Image

Websocket Essentials: Building apps with HTML5 websockets

By: Varun Chopra

Overview of this book

Table of Contents (13 chapters)
WebSocket Essentials – Building Apps with HTML5 WebSockets
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
6
Enhancing HTML5 Web Application Development Using Modern Tools
Index

Running server on mobile


Till now we were working on a local server and application, but to run the application on a mobile, we need to shift our client application code to a server in such a way that it will cater to the application from a server URL. For this we will take a simple example: basically, we are going to change an application we have already created. In Chapter 2, Getting Started with WebSockets, we developed an application for Echo test, which basically returns whatever we send to the server. Now let's see how it will work on a mobile phone.

Firstly, we will change the server code so that it caters to the client code. Here are the changes we will make on the server side:

var express = require('express');

var app = express()

var http = require('http').Server(app);

app.use(express.static(__dirname + '/public'));

app.get('/', function(req, res)
{

  res.sendfile('public/index.html');

});

http.listen(3000, function()
{

  console.log('listening on *:3000');

});

var WebSocketServer...