Reputation: 151
I am looking for a code strategy to be able to detect if multiple instances of my app are being ran across a LAN. I have tried searching for ideas but nothing pegs it and I ran out of search queries that make sense.
I am mostly starting off with just Swift code, but eventually will want to include C# under windows.
I suspect I have to generate a packet of somesort to broadcast itself across the LAN with a unique identifier and it detects that broadcast with identifiers that don't match?
I am not looking for a premade app that does this. I want to embed it into this code.
I don't want to block multiples from running, I just want to grab a statistics of use and send that out to my server that hosts the web interface for this app. (This part I have no issues with)
Upvotes: 1
Views: 108
Reputation: 16276
You can use sort of rendezvous server, a simple version of it adapted for your needs. You'd need to run a server on well known address listening to incoming connections and each instance of your application would register with it (e.g. by just connecting) on startup.
Broadcasting would be simpler but has also some limitations like difficulties to broadcast between subnets or wider.
Upvotes: 1
Reputation: 22073
Like you said, you could use UDP for this. Just broadcast a 'I am here' message. From there, you could setup a TCP connection to communicate between the applications.
After rereading your last paragraph, you could detect 2 instances on the same lan at your server, because they are all using the same (external) IP.
Upvotes: 1