无法打印控制台消息

时间:2016-06-01 12:53:49

标签: node.js mongodb socket.io cloud9-ide c9.io

我正在使用 c9.io

我正在使用 node.js socket.io mongodb ,这是我的服务器代码:

//
// # 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);
      });
    });
});

除非无法输入 io.sockets.on()功能,否则一切正常。 我在那个函数之前写了一个评论..

我试图在控制台中打印消息,它完美地工作.. 请帮忙

0 个答案:

没有答案