Advertisement

Connect Error (works in release, but not debug)

Started by April 10, 2003 02:06 PM
1 comment, last by 1kevgriff 21 years, 10 months ago
Hi. I'm working on a Winsock "Network Connection" class that handles all connections for a server, and can also run as a client. I have this code when starting up as a client:
    
int CNetworkConnection::StartNewClient(int port, char *IP)
{
	mainAddr.sin_family = AF_INET;
	mainAddr.sin_port	= htons(port);
	mainAddr.sin_addr.s_addr = htonl(INADDR_ANY);

	if (bind(mainSocket, (LPSOCKADDR)&mainAddr, sizeof(mainAddr)) == SOCKET_ERROR)
	{
		WSACleanup();
		return 1;
	}

	targetAddr.sin_family = AF_INET;
	targetAddr.sin_port = htons(port);
	targetAddr.sin_addr.s_addr = inet_addr(IP);

	if (targetAddr.sin_addr.s_addr == INADDR_NONE)
	{
		// add gethost stuff here

		cout << "TARGET ADDR NONE!" << endl;
	}

	// returns Error 5 here.. Access Denied

	if (connect(mainSocket, (sockaddr *)&targetAddr, sizeof(targetAddr)) == SOCKET_ERROR)
	{
		//WSACleanup();

		return 1;
	}

	// should be connected

	// start receive thread

	receiveRunning = TRUE;
	StartRecieve();

	return 0;
}
    
When (in debug) I call connect(), I get Error 5. I can WSAGetLastError() when coming out of the function. Now, if i run it in Release.. i get Error 10060 which is just a timeout. So it'll work in Release but not debug. Any idea why? I can post more code if needed. Thanks [edited by - Coaster Kev on April 11, 2003 10:47:27 AM]
What do you mean "but i''m not connecting to anyone in particular?" How does the function gets called if the program does not attempt to connect to a server?

Kuphryn
Advertisement
I found the error when i tried to connect to a friend''s computer, but when i was doing my own testing i was just putting the loopback address in for the IP. Disregard that sentence if it''s too confusing.

This topic is closed to new replies.

Advertisement