Skip to content

Socket.io Server Down client continues to pool #1824

@webmutation

Description

@webmutation

Created a small hello world app that emit hello world every 2s, but when I kill my node.js server the socket.io clients continue to pool, except IE9 I try to use socket.disconnect but that does not appear to work. Am i misusing this?

var app = require('http').createServer(handler)
var io = require('socket.io')(app);
var fs = require('fs');

app.listen(8080);

function handler (req, res) {
    fs.readFile(__dirname + '/client.html',
        function (err, data) {
            if (err) {
                res.writeHead(500);
                return res.end('Error loading client.html');
            }

            res.writeHead(200);
            res.end(data);
        });
}

io.on('connection', function (socket) {
    socket.emit('news', { msg: 'hello world!' });
    setInterval(function(){
        socket.emit('news', { msg: 'hello world!' });
    },2000);

    socket.on('my other event', function (data) {
        console.log(data);
    });
});

Server.js

<!DOCTYPE html>
<script src="/socket.io/socket.io.js"></script>
<script>
    var socket = io('http://localhost');
    socket.on('news', function (data) {
        console.log(data);
        addMessage(data.msg);
        socket.emit('my other event', { agent: navigator.userAgent });
    });

    socket.on('connect_error', function() {
        console.log('Got disconnect!');
        socket.disconnect();
    });

    function addMessage(msg){
        var node = document.createElement("li");
        var textnode = document.createTextNode(msg);
        node.appendChild(textnode);
        document.getElementById("messages").appendChild(node);
    }
</script>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<h1>SocketIO Test</h1>
<ul id="messages"></ul>
</body>
</html>

Client.js

Kill node.js

Client Errors

GET http://localhost:8080/socket.io/?EIO=3&transport=polling&t=1413201970852-46 net::ERR_CONNECTION_REFUSED socket.io.js:2680
Got disconnect! client.html:12
GET http://localhost:8080/socket.io/?EIO=3&transport=polling&t=1413201978852-47 net::ERR_CONNECTION_REFUSED socket.io.js:2680
Got disconnect! client.html:12
GET http://localhost:8080/socket.io/?EIO=3&transport=polling&t=1413201986852-48 net::ERR_CONNECTION_REFUSED socket.io.js:2680
Got disconnect! client.html:12
GET http://localhost:8080/socket.io/?EIO=3&transport=polling&t=1413201994852-49 net::ERR_CONNECTION_REFUSED socket.io.js:2680
Got disconnect! client.html:12
GET http://localhost:8080/socket.io/?EIO=3&transport=polling&t=1413202001884-50 net::ERR_CONNECTION_REFUSED socket.io.js:2680
Got disconnect! 

Do I have to handle this on my side or does socket.io handle this for me?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions