The short answer is you don't (at a protocol level).
Publishers and subscribers are totally unaware of each other, messages are sent to topics not to specific subscribing clients.
The slightly longer version:
You could do something with retained messages and LWT (Last Will & Testament)
e.g.
Each client publishes a retained message to the following topic
online/<clientID>
With a payload of true
when it connects. It also sets up LWT that will publish a payload of false
if the client is disconnected by a network fault. If the client cleanly disconnects then it will need to publish the false
payload as it's last action before going offline.
To tell if client is online you subscribe to the wildcard topic of online/+
and then check the last segment of the topic for clientid and the payload for the state.