nodejs socket.io socket file not close after disconnect

797 views Asked by At

I'm using node(v.0.12.4), socket.io(1.3.5) which is server. Server is Ubuntu 14.04 LTS.

Client is android using socket.io library which is compatibility socket.io 1.X.X (https://github.com/nkzawa/socket.io-client.java)

I have a question.

I run socket.io server(3305 port) and show list of file(lsof -i | grep 3305)

**COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME**

**node 135665 root 11u IPv6 516450 0t0 TCP *:3305(LISTEN)**

and client connect to socket.io server and show list of file(lsof -i | grep 3305)

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

node 135665 root 11u IPv6 516450 0t0 TCP *:3305(LISTEN)

node 135665 root 14u IPv6 516450 0t0 TCP *:ServerIP(xxx.xxx.xxx.xxx:3305)->AndroidIP(xxx.xxx.xxx.xxx:33972)(ESTABLISHED)

and android's network is changed, such as wifi to lte.

socket.io server disconnect android client because of pingTimeout(60sec). and show list of file(lsof -i | grep 3305)

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

node 135665 root 11u IPv6 516450 0t0 TCP *:3305(LISTEN)

node 135665 root 14u IPv6 516450 0t0 TCP *:ServerIP(xxx.xxx.xxx.xxx:3305)->AndroidIP(xxx.xxx.xxx.xxx:33972)(ESTABLISHED)

socket.io server source is

var io=new Server(3305);
io.sockets.on("connection",function(socket){
console.log("connection : "+socket.id);
socket.on("disconnect",function(){
console.log("disconnect : "+socket.id);
 });
});

I show that socket.io server disconnect client. why does it remain ESTABLISHED?

1

There are 1 answers

1
Guillermo Mansilla On

Try this

var io = new Server(3305);
io.on("connection", function(socket) {
    console.log("connection : " + socket.id);
    socket.on("disconnect", function() {
        console.log("disconnect : "+ socket.id);
    });
});