Advertisement
Guest User

Untitled

a guest
Aug 27th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. // Express modules requirements
  2. var express = require('express')
  3. , http = require('http')
  4. , path = require('path');
  5.  
  6. // Socket.IO module
  7. var io = require('socket.io');
  8.  
  9. // Some tweakering to get ot to work with Express 3
  10. var app = express();
  11. var server = http.createServer(app);
  12. var io = io.listen(server);
  13. io.set('log level', 1);
  14.  
  15. // Basic Express configuration
  16. app.configure(function(){
  17. app.set('port', process.env.WWW_PORT || 7000);
  18. app.set('views', __dirname + '/views');
  19. app.set('view engine', 'jade');
  20. app.use(express.favicon());
  21. app.use(express.logger('dev'));
  22. app.use(express.bodyParser());
  23. app.use(express.methodOverride());
  24. app.use(app.router);
  25. app.use(express.static(path.join(__dirname, 'public')));
  26. });
  27.  
  28. app.configure('development', function(){
  29. app.use(express.errorHandler());
  30. });
  31.  
  32. // Main route to deliver the static html
  33. app.get('/',function(req, res){
  34. res.render('index');
  35. });
  36.  
  37. // Object/dictionary in which we store the differents sockets
  38. var clouds = {};
  39.  
  40. // callback for websocket disconnetion
  41. var disconnetion = function() {
  42. console.log("Lost connection: " + socket.id);
  43. };
  44.  
  45. // callback for new websocket connection
  46. var connection = function(socket){
  47. console.log("New connection: " + socket.id);
  48.  
  49. // bind disconnect event
  50. socket.on('disconnect', disconnetion);
  51. };
  52.  
  53. // bind new connection event
  54. io.sockets.on('connection', connection);
  55.  
  56. // Let's start the server
  57. server.listen(app.get('port'), function(){
  58. console.log("Express server listening on port " + app.get('port'));
  59. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement