Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodejs & socket io : warn - error raised: Error: listen EADDRINUSE

I am giving a try to Node.js with socket.io

Now here is my scenario i am ubuntu 12.04 user and i have folder pp on desktop

inside that i am putted server file i.e app.js

Here is the content

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

Now in the same folder i have another file index.html like

<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>

when i am trying to run the app.js useing node like

 node app.js 

I am getting the error

 warn  - error raised: Error: listen EADDRINUSE

I go through some doc and found that port are busy so restarted the system but still i am getting the same error .

Please tell me what might i am doing wrong .

like image 401
masterofdestiny Avatar asked Feb 01 '13 13:02

masterofdestiny


1 Answers

Try another port. 8080 is usually used by tomcat e.g.

Use netstat -a -v to know which port are currently used.

like image 186
Charles Avatar answered Sep 28 '22 03:09

Charles