how to send host name to client?
Jul 8, 2013 at 3:32pm UTC
I have a server and client program. The server sends its IP address to a master web server. The client then reads this list and displays the IP addresses in a listbox. The client can then select a server and connect to it. But i also want to display the server's host name next to the IP address in the client listbox.
here is the code to send the IP address:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
if (gethostname(ac, sizeof(ac)) == SOCKET_ERROR)
printf( "Error when getting local host name: ", WSAGetLastError());
struct hostent *phe = gethostbyname(ac);
if (phe == 0)
printf( "Error: ", WSAGetLastError());
struct in_addr addr;
memcpy(&addr, phe->h_addr_list, sizeof( struct in_addr)); // use the first ip-address
printf( "IP used by Server: %s\n", inet_ntoa(addr)); // inet_ntoa(addr) provides the local address.
MyIP = inet_ntoa(addr);
sprintf(SendBuf, "%hhu|%s", cAddIP, MyIP); // Send the server the IP
WebPost(WEBSITE, WEBPAGE, SendBuf, 0);
what do i need to do to also send the host name?
Jul 8, 2013 at 4:16pm UTC
You already have the local hostname, it was returned to you in Line 2 of this code snip. You should send it the same way you are sending the IP. It would help if you posted the code for "WebPost".
Topic archived. No new replies allowed.