0

I have two programs So if i have one program "local" on machine A and another "remote" on machine B how can program "local" find out whether they both are running on same machine or different machine in c++ under windows environment.

4

2 回答 2

1

Send the IP address of "self" from "local" to "remote"? Or let "remote" send it's IP address to "local". Then compare with "its own" IP address. If they are the same, then must be the same machine [or the machine has multiple network cards connected to the same overall network].

Ask for some other machine specific ID, such as mac-address, hard disk ID, etc.

There are myriad of different methods that may or may not work, depending on what you are actually trying to do.

Edit based on comment:

If you want to check if the program is available on the same machine, you could use a "named pipe" or some other named IPC mechanism, and simply check if the named IPC is available on the local machine. If not, use remote machine mechanism (e.g. TCP/IP).

于 2013-03-31T01:48:25.113 回答
0

i am actually looking fro something like if i have two program sending data to each other then if one process is local to another they will use local ipc methods but if they are remotly located then tcp/ip. so how can i detect about the program and then use it to decide which method for communication to use

Try local IPC methods first. If they don't work, switch to TCP/IP.

于 2013-03-31T01:54:06.467 回答