The problem is over-complicated. A much straightforward solution is to redesign as Uwe and David suggested:
(1) Worker app. (2) Long-running TcpServer, that awaits clients and calls workers (3) Clients.
========================
I would like to build a SampleApp
that functions as:
- When started, it checks if there is already
SampleApp
running; - If not, it starts a
TcpServer
, aTcpClient
, passes certain command from itsTcpClient
to itsTcpServer
, does the work, closes theTcpServer
, and quits; - If yes, it starts a
TcpClient
, passes the command to the other'sTcpServer
and quits. (The other'sTcpServer
will do the work.) - There may be multiple
SampleApp
started when the first one is still running.
I have no idea about how to solve this problem practically, for example :
- Which architecture to start with ? ( The reputed OmniThreadLibrary seems to deal with thread-based concurrency instead of OS-process-based concurrency. )
- There is no
SampleApp
running. TwoSampleApp
are started (almost) simultaneously. How to guarantee only one TcpServer is started? (There is no "global list" to register the incoming "players".) - There is one
SampleApp
running. How to handle if a 2nd detects the 1st's mutex and thus decides to be a TcpClient, but the 1st stops its TcpServer and quits?
Any insights are appreciated!