开发者

How can two instances of an application communicate in Java?

I am developing a new Java Desktop app. Something like a media player. I want to loa开发者_运维知识库d 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


You could use ports.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜