My server is up and running (connecting through telnet worked so I know its functional) but my client cannot seem to establish a connection. I have a feeling it has something to do with the way I'm filling out the sockaddr_in serverAddr struct.
Can anyone please help? Thank you.
int clientSocket;
char hostname[256];
struct sockaddr_in serverAddr;
struct hostent *host;
socklen_t theirAddrSize;
gethostname(hostname, sizeof(hostname));
host = gethostbyname(hostname);
memset(&serverAddr, 0, sizeof(serverAddr));
serverAddr.sin_family = AF_INET;
serverAddr.sin_addr.s_addr = inet_addr( host->h_name );
serverAddr.sin_port = htons( 30000 );
if ( clientSocket = socket( AF_INET, SOCK_STREAM , 0 ) == -1) {
cerr << "socket failed ; exiting..." << endl;
exit(1);
}
if ( connect( clientSocket , (struct sockaddr *) &serverAddr , sizeof(serverAddr) ) == -1 ) {
cerr << "connect failed ; exiting..." << endl;
exit(1);
}
connect always returns -1.