Nodejs & socket io Error: listening to EADDRINUSE

I'm trying to chat with Node.js and socket.io

Now here is my script, I am using ubuntu 12.04 user and I have pp folder on the desktop

inside that i put the server file server.js

Here is the client:

$(document).ready(function() {
    var urlServer = location.origin + ':8081';
    var socket = io.connect(urlServer);
});

$(document).ready(function() {
    var urlServer = location.origin + ':8081';
    var socket = io.connect(urlServer);

    $("#boton").on('click', function() {
        var mensaje = $("#mensaje").val();
        socket.emit("mensaje", {msg: mensaje});
    });

    socket.on("mensaje", function(msg) {
        console.log("hemos recibido un mensaje", msg);
    });
});

And here is the server

var server  = require('http').createServer(),
    sio      = require('socket.io'),
    port    = 8081;
server.listen(port);
var io = sio.listen(server, { log:true });
var channels = {};
io.sockets.on('connection', function (socket) {
    console.log("Cliente conectado");

    socket.on('mensaje', function (msg) {
        console.log(msg);
    socket.broadcast.emit('mensaje', msg);
    });

});
console.log('1- Escuchando en http://localhost:' + port , "");
console.log("");

Now in the same folder I have an html file, for example

<!DOCTYPE html>
<html>
<head>
    <script src="../jquery.js"></script>
    <script src="../node_modules/socket.io/node_modules/socket.io-client/dist/socket.io"></script>
    <script src="clientechat.js.js"></script>
    <title>Chat con Node</title>
</head>
<body>

    <div id="mensajes"></div>
    <input type="text">
    <input type="submit" id="boton">

</body>
</html>

when i try to run app.js using node like

node server.js

I get an error

   warn  - error raised: Error: listen EADDRINUSE

I am trying to restart everything but not working

Please tell me what I can do wrong.

+4
source share
5 answers

, , . - , .

@Faisal Ameers Linux, , .

, : fooobar.com/questions/10715/...

OS X: fooobar.com/questions/12190/...

+3

, , . ;

Command:
ps -eaf|grep node

Output:
root     28029 27332  0 14:25 pts/2    00:00:03 node myVNC.js

, node, "28029"

,

kill -9 28029
+10
+1

, , listen(port). listen() EADDRINUSE, listen() .

server.listen(port); var io = sio.listen(server, { log:true });

0
0

All Articles