moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 509 forks source link

Detect when a client loses connection without closing it #552

Closed pirakleous closed 7 years ago

pirakleous commented 7 years ago

Hello, i want to ask if it is possible to receive clientDisconnected message when a client loses its connection or shutdown.

mcollina commented 7 years ago

in what sense you want to receive a message? from the broker?

pirakleous commented 7 years ago

in clientDisconnected event of broker. when shutdown a client (esp8266) without closing the connection it takes too match time to realise that the client is disconnected.

mcollina commented 7 years ago

That is mostly related to your kernel network stack, tcp timeouts and so on. There is not much you can do from the Node point of view.

You might consider setting https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback and https://nodejs.org/api/net.html#net_socket_setkeepalive_enable_initialdelay.

The tcp socket is on the stream property of https://github.com/mcollina/mosca/blob/master/lib/client.js#L42

https://github.com/mqttjs/mqtt-connection/blob/master/connection.js#L29.