I'm working on a network-based application. The application server will have many remote clients connected to it at one time, and each client will need to be able to authenticate, and then call various functions on the application server. Some of these functions will need to send messages to other clients.

RMI seems like a really cool way to handle this, except that it does not seem to provide some things I need:

1. How do I send a message from one client to another client, or to all other clients? Is there a list of current client connections somewhere in the RMI server implementation that I'm missing? I can imagine creating a queue system and having remote clients poll for messages, but that seems terribly inefficient. Is there any way for an RMI server to "notify" a client that there are messages on the server waiting to be picked up?

2. Can the RMI server know when an individual client has connected and disconnected? I need to keep a running list of which clients are currently connected and which have gone away, and there does not seem to be any way to notify the server implementation when an individual client has disconnected.

I started this project writing a custom TCP server to handle this, and then I stumbled on RMI and it is such a nice way of doing things that I'd really like to use it, but these questions are show-stoppers - I really need inter-client communication to be possible and efficient, and I need to know when clients come and go.

Thanks!