Question about sockets in client-server model
I am a newbie in socket programming, and I wanted to create a client-serve model using sockets in C language. Server is my PC and client is my laptop.
I found some example code on the net, but there's something I dont understand and would like to ask.
The code i found is available in Linux Howtos: C/C++ -> Sockets Tutorial when I searched it on the net..
Now my question is, when the client says
How/where does it find my PC and its hostname? In the desription of this function it says: "The gethostbyname() function searches the database and finds an entry which matches the specified host name, opening a connection to the database if necessary. "
server = gethostbyname(argv);
My question is what/where is this database? Is it setup when PC starts using the connection? How can the client query if a server with my PC's hostname exists? Can you plz explain this simply??
PS. can you also explain
Isnt s_addr the IP address of the server? But it writes on net that "anyone from any network can connect, using any IP address bound to the PC" by using this macro, then is this not the IP address of the server in reality? Can you plz clarify this also?
serv_addr.sin_addr.s_addr = INADDR_ANY;