File: connected-users-websocket/server.js

Recommend this page to a friend!
  Classes of Igor Escobar   Terminal Crossword   connected-users-websocket/server.js   Download  
File: connected-users-websocket/server.js
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Terminal Crossword
Generate a crosswords board on a text console
Author: By
Last change:
Date: 2 years ago
Size: 711 bytes
 

Contents

Class file image Download
var express = require("express") , app = express() , http = require('http') , server = http.createServer(app) , io = require('socket.io').listen(server); app.set('view options', {layout: false}); app.set('view engine', 'jade'); app.set('views', __dirname + '/views'); app.use(express.static(__dirname + '/public')); app.get('/', function(req, res){ res.render('index.jade', {}); }); server.listen(8080); var activeClients = 0; io.sockets.on('connection', function(client){ activeClients += 1; io.sockets.send(activeClients) client.on('disconnect', function(){ clientDisconnect(client); }); }); function clientDisconnect(client){ activeClients -=1; io.sockets.send(activeClients) }