Jump to content
  • Advertisement
Sign in to follow this  
Khaos Dragon

winsock connect problems

This topic is 5470 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
		return false;

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!