File: multiplayer-drawing-board/app.js

Recommend this page to a friend!
  Classes of Igor Escobar   Terminal Crossword   multiplayer-drawing-board/app.js   Download  
File: multiplayer-drawing-board/app.js
Role: Example script
Content type: text/plain
Description: Example script
Class: Terminal Crossword
Generate a crosswords board on a text console
Author: By
Last change:
Date: 2 years ago
Size: 739 bytes
 

Contents

Class file image Download
var app = require('http').createServer(handler) , io = require('socket.io').listen(app) , static = require('node-static') , fileServer = new static.Server('./'); app.listen(8080); function handler(request, response) { request.addListener('end', function () { fileServer.serve(request, response); }); } io.set('log level', 1); io.sockets.on('connection', function (socket) { var currentIdPackage = {"id": socket.id}; io.sockets.send(JSON.stringify({"register_user": currentIdPackage})); socket.on('mousemove', function (data) { socket.broadcast.emit('moving', data); }); socket.on('disconnect', function(){ io.sockets.send(JSON.stringify({"unregister_user": currentIdPackage})); }); });