-2

I font this solution to listening the internal ping pong. Internal library of Socket.io i.e. engine.io triggers the 'heartbeat' event after sending pong event to client. you can listen to this event using following hack.

I tried to override the socket.io in new file but it not work. currently following code works for me.

Er. Mohit Agrawal
  • 2,116
  • 1
  • 17
  • 15
  • your question is unclear , though you have posted your answer,And your question says about code snippet but there is no code snippet in your code..looks like your question incomplete to understand.? – vijay Feb 19 '16 at 11:14
  • actually I want to listen to the pong sent by server when client send the ping in case of in activity to maintain the socket connection live. – Er. Mohit Agrawal Feb 20 '16 at 14:12

1 Answers1

0

You can use following code also, without overriding the internal working.

socket_io = require('socket.io');

io = socket_io.listen(server, {pingTimeout : 60000, pingInterval : 15000});

//Listening to heartbeat of internal socket ping pong
io.engine.on('connection', function(socket_conn) {

    socket_conn.on('heartbeat', function(){

        manager.resetTimer(socket_conn.id);

    })
});
Er. Mohit Agrawal
  • 2,116
  • 1
  • 17
  • 15