答案 0 :(得分:0)
将server.listen(...)
放在最后。此外,您的socket
(=require(...)
)声明似乎已关闭。将其更改为var io = require('socket.io').listen(server);
代码是:
var server = require( 'http' ).createServer();
server.listen( 4444 );
var socket = require( 'socket.io' );
var io = socket.listen( server );
console.log('Started!');
io.on('connection', function(socket){
console.log('Connected');
socket.on('message', function(data) {
console.log('Debug!');
});
});
应该是:
var server = require( 'http' ).createServer();
var io = require('socket.io').listen(server);
console.log('Started!');
io.on('connection', function(socket){
console.log('Connected');
socket.on('message', function(data) {
console.log('Debug!');
});
});
server.listen( 4444 );