0

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 ?

Daniel Del Core
  • 3,071
  • 13
  • 38
  • 52
  • I'm not sure I understand what you're asking - you want to "get *my* hostname to connect to the server"... You shouldn't really need "your" (the client's) hostname to connect to the server, just the *server's* hostname. – Edward Thomson Jun 02 '12 at 17:27
  • yeah sorry im a little bit confused :S. I mean when i run my client i need to input a hostname, but i have no idea what that hostname is.@EdwardThomson – Daniel Del Core Jun 02 '12 at 17:29

1 Answers1

1

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.

bmargulies
  • 97,814
  • 39
  • 186
  • 310