我給一個嘗試的Node.js與socket.io和的NodeJS插座IO:警告 - 錯誤提出:錯誤:聽EADDRINUSE
現在,這裏是我的情況我是Ubuntu的12.04用戶,我對文件夾頁桌面
裏面,我很推杆服務器文件即app.js
這裏是在同一個文件夾中我還有一個index.html文件,如內容
var fs = require('fs')
, http = require('http')
, socketio = require('socket.io');
var server = http.createServer(function(req, res) {
res.writeHead(200, { 'Content-type': 'text/html'});
res.end(fs.readFileSync(__dirname + '/index.html'));
}).listen(8080, function() {
console.log('Listening at: http://localhost:8080');
});
socketio.listen(server).on('connection', function (socket) {
socket.on('message', function (msg) {
console.log('Message Received: ', msg);
socket.broadcast.emit('message', msg);
});
});
現在
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
$(function(){
var iosocket = io.connect();
iosocket.on('connect', function() {
$('#incomingChatMessages').append($('<li>Connected</li>'));
iosocket.on('message', function(message) {
$('#incomingChatMessages').append($('<li></li>').text(message));
});
iosocket.on('disconnect', function() {
$('#incomingChatMessages').append('<li>Disconnected</li>');
});
});
$('#outgoingChatMessage').keypress(function(event) {
if(event.which == 13) {
event.preventDefault();
iosocket.send($('#outgoingChatMessage').val());
$('#incomingChatMessages').append($('<li></li>').text($('#outgoingChatMessage').val()));
$('#outgoingChatMessage').val('');
}
});
});
</script>
</head>
<body>
Incoming Chat: <ul id="incomingChatMessages"></ul>
<input type="text" id="outgoingChatMessage">
</body>
當我試圖運行app.js期運用節點像
node app.js
我收到錯誤
warn - error raised: Error: listen EADDRINUSE
我通過一些文檔,發現端口都很忙
所以重新啓動系統,但仍然收到相同的錯誤。
請告訴我我做錯了什麼。
嘗試另一個端口 - 可能'8080'被其他應用程序使用。 – pimvdb
我真的有這個問題,我找不到任何解決方案。 – Tarek
它似乎沒有編輯server.js文件中的端口,所以我通過了該錯誤,但現在無法正確連接。 – Tarek