Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

socket.io-client holds the running status after a while on disconnection

socket.io-client holds the running status after a while on disconnection

Problem

server.js

var io = require('socket.io').listen(3000);

io.sockets.on('connection', function (socket)
{
    console.log("server is connected");
    socket.on('disconnect', function ()
    {
        console.log("disconnected");
    });
});

client.js

var socket = require('socket.io-client')
            .connect('http://localhost:3000/')
            .on('connect', function ()
            {
                console.log("client connected");
                socket.disconnect();
            })
            .on('disconnect', function ()
            {
                console.log('client disconnected');
                //not going to finish the client.js app imediately.
            });

Why?

socket.io-client holds the Running Status about 1 minutes after the disconnect event.

Is there any fundamental fix or smart workaround?

node.js v0.8.8

socket.io v0.9.10

socket.io-client v0.9.10

Problem courtesy of: Ken OKABE

Solution

Seems like a bug to me. If you don't want to wait you can do process.exit() in disconnect callback.

Solution courtesy of: vinayr

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

socket.io-client holds the running status after a while on disconnection

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×