Create a project folder for our code. Inside it, create a new directory named
server
.Use a terminal or the shell command prompt to change the directory into our newly created folder.
Type the following command that will install a WebSocket server:
npm install --save ws
Create a new file named
server.js
under theserver
directory with the following content:var port = 8000; // Server code var WebSocketServer = require('ws').Server; var server = new WebSocketServer({ port: port }); server.on('connection', function(socket) { console.log("A connection established"); }); console.log("WebSocket server is running."); console.log("Listening to port " + port + ".");
Open the terminal and change to the server directory.
Type the following command to execute the server:
node server.js
You should get the following result if this works:
$ node server.js WebSocket server is running. Listening to port 8000.
HTML5 Game Development by Example: Beginner's Guide
By :
HTML5 Game Development by Example: Beginner's Guide
By:
Overview of this book
Table of Contents (18 chapters)
HTML5 Game Development by Example Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
Introducing HTML5 Games
Getting Started with DOM-based Game Development
Building a Card-matching Game in CSS3
Building the Untangle Game with Canvas and the Drawing API
Building a Canvas Game's Masterclass
Adding Sound Effects to Your Games
Saving the Game's Progress
Building a Multiplayer Draw-and-Guess Game with WebSockets
Building a Physics Car Game with Box2D and Canvas
Deploying HTML5 Games
Pop Quiz Answers
Index
Customer Reviews