Reputation: 3221
Hello i've just picked up sockets for the first time and im using this tutorial to learn the basic steps....
http://www.linuxhowtos.org/C_C++/socket.htm
Everything seems to work fine so far, but my problem is im unsure of how to get my hostname to connect to the server from the client. Is there a way i can output the hostname on the server side ?
Upvotes: 0
Views: 2656
Reputation: 100051
By definition, the client isn't connected to the server until you connect them. So, for the client to discover the identity of the server, you have to use some other protocol. The common, simple, case, is of course DNS. You create a DNS entry for myservice.mydomain.com and let the client look it up.
There are other service discovery protocols out there if your client can't 'know a name', such as Bonjour. The general class of protocol here is described on Wikipedia under
http://en.wikipedia.org/wiki/Zero_configuration_networking
If everyone is on the same machine, then the hostname is the literal string 'localhost', which maps to IP 127.0.0.1.
Upvotes: 1