tags:

views:

80

answers:

3

Hi!

We have written a client-server programme. Programme is running fine when we run both client and server on the same machine on different terminals by calling gethostbyname(127.0.0.1). We have to communicate between different machine. So my question is, how to determine the IP of the other machine (server's), and how to find out the IP of one's own machine. Is it simply chosen as something we wish? How to get hostname of the server and one's own machine?

Thanks

A: 

It's not clear what platform you are operating on but for Unix/Linux you can discover the IP addresses assigned to the interfaces on your system with the ifconfig command (you may need to be root to get to this, it's often found in the sbin folder), on Windows ipconfig will get you the same information.

Ideally you'd have domain name resolution set up on your network and would have a 'name' for the server, i.e. server.mydomain.com then you could use gethostbyname("server.mydomain.com"). For more information on domain name services (dns) you could do worse than start here: http://en.wikipedia.org/wiki/Domain_name_system

Lazarus
i am working in unix envoirement.we are connected thrugh lan wire which is connected into a hub.should we make a direct connection between the two machine or above connection will work?our programme is simply written in c.
mawia
The above connection will work, it's much better than a direct link architecturally. I'd suggest that you get a copy of TCP/IP Network Administration published by O'Reilly to get a better understanding of Unix networking (http://oreilly.com/catalog/9780596002978/), that'll help you have a solid base of understanding to allow you to build on top of it.
Lazarus
A: 

You cannot get the IP of the other machine in some magical way; you either have to know it or develop some sort of broadcast protocol in your network app, where the server or clients broadcasts their IP.

Getting your own IP depends on your platform and what language you use.

Rolle
A: 

If this is a client/server environment, so the client is going to need to know the server address.

If you are using gethostbyname, then the name resolution systems that are actually supported (DNS, NIS, etc.) will vary by OS and system configuration.

The most common configuration is to use DNS. In this case, it is worth noting that the server cannot easily discovery its own name on the network (or name itself). This is because the naming service that the client will use is external to the server. The server has a local idea of what its hostname and it's resolver's default domain, but they are not necessarily the FQDN that DNS externally maps to the server's IP addresses.

benc