In high level terms consider this option. The Client and Server programs both open ServerSockets and act as clients to each other. If this is a bit confusing at first, do some simple tutorials on socket clients & servers, or find a friend and role-play the two machines.
Lots of moving parts, no? And I left out any way to log out. The client might tell the server it is logging out so the server can remove the client from the list of logged in clients. Or the server might try to connect to a client and fail, meaning the client is no longer running. That would be a sign to remove the client from the list of logged in clients, too. Hope that helps!
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi