i have a server program running. now i need to specify the ipaddress of this server in a txt file. the client program reads the user defiened ip adress when it starts and connects to the server. this work OK, but
instead of this way of operation, i want a function in the client program to read the ipaddress of the server program to a variable in the client program
which then use the value of this variable to connect to the server
the reason for wanting this function instead is that the server address will vary for different users
and it is better to have it automaticely detected in order to get rid of the txt file and the following user installation problems
the installation process will be much cleaner with this approach
is there anyone who can give me some ideas on how to do this?
a c++ code examples would be great as i am quite new with c++
can i i.e. read the register or other system variables by referring the server name. the name of my server program is i.e rioc.exe
the server and client program are both win32 app, not concole
I don't think you can do that. The whole point of client/servers is that they can be disconnected and that the client can connect to any number of servers that are all different by inputting the IP of the one they want to connect to.
If your IP won't change, then just hard code it into the program. If it changes, there is no way to get it.
the server address don't change per user. it is the same every time let say USER A start up the server on his specific local network, but the addresst is different ( or most likely ) different for USER X when he is running the server program on his localnetwork.
i should maybe say that the server and client are always running on the same pc.
so instead of reading the server ip address in a server info window and write this to a txt file for the client to pick it up and use it for connecting to the server this should be done automatically
i can't hardcode it in the client as other users will have a different server address than i have.
the program is not for myself on my pc only, but will be used by others on different localarea network setups.
If your server is running on something where it can dictate the host name then you can leave it up to DHCP to resolve the address. In this method your client only tries to connect via a host name so it doesn't matter what the IP actually is.
You could try a multicast*. In this idea either side, client or server, screams garbage at everything on the network. The other end has a socket open waiting for this and knows where to connect when it receives the message. DO NOT USE THIS METHOD, I only put it here in the interest of completeness.
*: I am not responsible for any injuries that you will probably suffer from angry sys admins chasing you down with pitchforks and torches if you choose to use this method.