freshworkstudio / gps-tracking-nodejs

Let you work with some GPS trackers that connects through tcp.
MIT License
262 stars 161 forks source link

How to know the device logout and actually stopped sending the packets #29

Open jAddict7 opened 5 years ago

jAddict7 commented 5 years ago

When a device sending packets to server A and its changed to server B. Whether server A is able to know the device is logged out completely?

In server.js,

connection.on('end', function(){
    _this.devices.splice(_this.devices.indexOf(connection), 1);
    connection.device.emit('disconnected');
});

In device.js,

this.on('disconnected', function(){
    _this.logout();
});

this.logout = function(){
    this.do_log('Device has been logged out.');
    this.loged = false;
    this.adapter.logout(); // No code in gt06n

    // code to send server as the device_id logout
};

But disconnected event is running very often. Is there a better solution to identify the device got disconnected completed?