I am developing a new Java Desktop app. Something like a media player. I want to load most of the resources in the background when the computer starts up. But the users can turn this option off form within the app or using some other utility. So, what I want to do is if a ban instance of the app is already running and the user starts the app again then I can communicate with the already running instance so that it can launch a new window?
The most known way to do that is to open a ServerSocket when first application starts on a well known port.
If ServerSocket fails to load, it's probably because an instance is already running.
In such a case, you can open a Socket and start to communicate your orders between both instances.
But you can also use far more sophisticated solutions, like Jini or JGroups.
Write the app so it has a server part
When it starts up, try to communicate to the server (if it is already running), and if that works, then the server should open a new window, and the client should die
This should give you an overview:
http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With