winsock connect problems

Started by
1 comment, last by kuphryn 19 years, 7 months ago
I am having no problem with my winsock code when running the server and clients on the same computer. However, when my clients are on different computers, they cannot seem to connect at all... I have tried turning off firewalls for both computers, so I am not what the problem is. The following is the code I use, maybe there is something inherently wrong in there?

bool	request_connection( char* ip_address, int port)
{
	SOCKADDR_IN saRemote;
	LPHOSTENT lpHostEntry;
	
	////making remoteSocket a stream tcp type
	remoteSocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );   
	if ( remoteSocket == INVALID_SOCKET )
		error_log<<"could not create stream socket"<<endl;
	///now getting address to connect to...
	lpHostEntry = gethostbyname( ip_address );
	if (lpHostEntry == NULL)
		error_log<<"could not find host"<<endl;		
	///filling in fields for address structure...
	saRemote.sin_family = AF_INET;
	saRemote.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);								
	saRemote.sin_port = htons( port );	
	//trying to connect to server...
	if( connect(remoteSocket, (LPSOCKADDR)&saRemote, sizeof(struct sockaddr)) != SOCKET_ERROR )
	{
		error_log<< "--Connected on server--" << endl;
		connected_to_server = true;
		return true;
	}
	else	
		return false;
}

Advertisement
Are you behind a router ?

If so, that would be your problem. A similar post in the forum .

Gizz
Try passing in AF_UNSPEC instead of AF_INET.

Kuphryn

This topic is closed to new replies.

Advertisement