I’ve done all my testing for my basic chat server and client by using this in the client code:
struct sockaddr_in server;
struct hostent * hp;
server.sin_family = PF_INET;
hp = gethostbyname( "localhost" );
if ( hp == NULL )
{
perror( "Unknown host" );
return EXIT_FAILURE;
}
The emphasis is on the “localhost.” This code has worked fine. Now I’m trying to test it between two computers, and I’m uncertain how to specify the name/address of the server I’d like to connect to. What needs to be changed?
Nothing need to be changed. Just replace
"localhost"by"192.168.0.1"or"stackoverflow.com"and it should work.Please note that
gethostbynameif flagged as obsolete and should be replaced bygetaddrinfo.Edit
getnameinfo->getaddrinfo