I am using c9.io.
I am using node.js, socket.io and mongodb and here is my server code :
//
// # SimpleServer
//
// A simple chat server using Socket.IO, Express, and Async.
//
var http = require('http');
var path = require('path');
var async = require('async');
var socketio = require('socket.io');
var express = require('express');
var mongoClient = require("mongodb").MongoClient;
var port = process.env.PORT;
var ip = process.env.IP;
//
// ## SimpleServer `SimpleServer(obj)`
//
// Creates a new instance of SimpleServer with the following options:
// * `port` - The HTTP port to listen on. If `process.env.PORT` is set, _it overrides this value_.
//
var router = express();
var server = http.createServer(router);
var io = socketio.listen(server);
router.use(express.static(path.resolve(__dirname)));
server.listen(process.env.PORT || 3000, process.env.IP || "0.0.0.0", function(){
var addr = server.address();
console.log("Chat server listening at", addr.address + ":" + addr.port);
});
//mongoose connect
mongoClient.connect("mongodb://" + ip + ":" + 27017, function(err){
if(err) throw err;
//couldnt ENTER THIS FUNCTION!!
io.sockets.on('connection', function(socket){
console.log('DONE!');
socket.on('input', function(data){
console.log(data);
});
});
});
Everything works perfectly except in that couldn't enter io.sockets.on() function.. I wrote a comment before that function..
I have tried to print message before it in the console and it works perfectly.. Any help please