This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
One way to do this would be to have the Server keep a list of all clients. You would probably maintain a list of sockets to each of the clients. Then you will iterate through the list of sockets and send the message to each one. Let us know how things work out with this, or if you think of anything yourself.
I have the same question. Is it really a good idea to have opened sockets to all clients? I'm closing mine so there is my problem. I don't know when the Applet in this case have closed. If you come up with any solutions to this I would be glad the see it.
Joined: Dec 06, 2001
If you want to be able to communicate with the client, it seems to me that you have to have an open socket connection. Unless you have some way to reopen the socket with the same client, then you will need to maintain an open connection.
In my work, the client is a browser and the server is a big AIX box. To send messages from the server to the client we reverse the roles ... the browser becomes the server and the AIX box becomes the client.
The browser has an applet that holds a ServerSocket open. At logon the browser tells the AIX box its ServerSocket address and the AIX box keeps a list of all the applet servers. To broadcast a message to a user, the AIX box looks up the addres for that user's applet, opens a socket and sends the message. To send to all users, it repeats open-send-close for each registered applet.
Does that sound interesting?
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