Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Express modules requirements
- var express = require('express')
- , http = require('http')
- , path = require('path');
- // Socket.IO module
- var io = require('socket.io');
- // Some tweakering to get ot to work with Express 3
- var app = express();
- var server = http.createServer(app);
- var io = io.listen(server);
- io.set('log level', 1);
- // Basic Express configuration
- app.configure(function(){
- app.set('port', process.env.WWW_PORT || 7000);
- app.set('views', __dirname + '/views');
- app.set('view engine', 'jade');
- app.use(express.favicon());
- app.use(express.logger('dev'));
- app.use(express.bodyParser());
- app.use(express.methodOverride());
- app.use(app.router);
- app.use(express.static(path.join(__dirname, 'public')));
- });
- app.configure('development', function(){
- app.use(express.errorHandler());
- });
- // Main route to deliver the static html
- app.get('/',function(req, res){
- res.render('index');
- });
- // Object/dictionary in which we store the differents sockets
- var clouds = {};
- // callback for websocket disconnetion
- var disconnetion = function() {
- console.log("Lost connection: " + socket.id);
- };
- // callback for new websocket connection
- var connection = function(socket){
- console.log("New connection: " + socket.id);
- // bind disconnect event
- socket.on('disconnect', disconnetion);
- };
- // bind new connection event
- io.sockets.on('connection', connection);
- // Let's start the server
- server.listen(app.get('port'), function(){
- console.log("Express server listening on port " + app.get('port'));
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement