Node.js - Socket.IO 1.0 - Timeout event

前端 未结 1 1970
不思量自难忘°
不思量自难忘° 2020-12-18 17:21

I\'m using Socket.IO (the latest version 1.1.0) to exchange messages with an Android app (the client). I would like to set a timeout (5s for example) to check if my client

相关标签:
1条回答
  • 2020-12-18 17:52

    That's not what the timeout setting handles. The timeout is how long the server will wait for a re-connect before it tears down that connection. You probably don't want to set it that short; possibly even leave it at the default.

    Socketio automatically sends heartbeats by default. You really should just need to assign a function to run when the 'disconnect' message is received on the server side.

    io.on('connection', function(socket){
           console.log('a user connected');
           socket.on('disconnect', function(){
               console.log('user disconnected');
           });
    });
    

    Check out this post for more information about the heartbeat: Advantage/disadvantage of using socketio heartbeats

    0 讨论(0)
提交回复
热议问题