Reputation: 2719
I have been trying to learn socket programming in C++ and got some progress for the basics. But I understood that basics are not fundamentals.
One of those fundamentals is about the question which is stated in the title. Lets say I have two separate applications running on the same computer. One of them has a server socket and the other one has a client.
When the server gets an IP address automatically, how can client find the server? Do I have to assign an IP address that is known by the client? In that case, maybe that IP address is not available on the network.
Or can client find and connect to the server by sone kind of name or id?
Upvotes: 0
Views: 400
Reputation: 310883
The IP address of any server in the same host is 127.0.0.1 unless the server has bound to a specific, different IP address. As @MartinJames points out, you can use 'localhost' as the hostname for that, except on certain broken Linux distributions.
Upvotes: 0
Reputation: 24847
Have the server bind to all interfaces and have the client lookup 'localhost' by name; it's resolved locally, (ie. no external DNS service required), to an IP address stored in a 'hosts' file, and is set by default to 127.0.0.1
Google 'hosts file'
Upvotes: 1