1
這是我在NodeJs
和i'上的冷杉程序,試圖在此上使用Express
和Socket.io
。創建簡單的項目後,如下面的代碼,我得到Nodejs get throw er; //未處理'錯誤'事件
throw er; // Unhandled 'error' event
錯誤,我是谷歌更多的教程,但我不能找到什麼我的代碼問題
安裝軟件包:
{
"name": "signalAndroidServerApplication",
"version": "0.0.0",
"private": true,
"dependencies": {
"body-parser": "~1.12.4",
"cookie-parser": "~1.3.5",
"express": "~4.12.4",
"socket.io": "latest"
}
}
我的NodeJS:
var socket = require('socket.io');
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = socket.listen(server);
var port = process.env.PORT || 3000;
server.listen(port, function() {
console.log('Server listening at port %d', port);
});
io.on('connection', function (socket) {
socket.on('new_count_message', function (data) {
console.log('new_count_message' + data);
io.sockets.emit('new_count_message', {
new_count_message: data.new_count_message
});
});
});
完全錯誤:
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:901:11)
at Server._listen2 (net.js:1039:14)
at listen (net.js:1061:10)
at Server.listen (net.js:1135:5)
at Object.<anonymous> (/var/www/signal/nodeJs/server.js:8:8)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
真正的錯誤是'EADDRINUSE' - 地址已在使用。 – deceze
'''EADDRINUSE'''表示端口已被使用。 –