2

I am using mqtt and mosquito broker to build a simple instant chat for an android platform. Now I wanted to implement a condition where any client can check if another client is online.

I know about Last will and testament but I wanted a user to be detected offline only wen the application is inactive or the user is not currently using the app.

I actually dnt need any code, buh wanted an idea as to how to implement this and I would be much grateful.

hardillb
  • 54,545
  • 11
  • 67
  • 105
George
  • 1,086
  • 14
  • 48
  • You can set the LWT topic manually when the app is closed (in fact you have to do this anyway because the LWT will only fire if the client goes off line due to a network issue/crashing) – hardillb Jan 26 '17 at 20:17

1 Answers1

3

You can do this without relying on MQTT internals which is much easier in my view. With this approach, you have much more control over what is going on:

The client can periodically send a message within another topic to inform the server of its availability. In case the server does not receive that message after a specified amount of time, it can assumed that it is offline.

The client can also send another message if the user logs out and inform the server a well.

If you insist on using MQTT internal structure, you may find this question useful: How to Find Connected MQTT Client Details

Community
  • 1
  • 1
Mehdi
  • 186
  • 2
  • 8