accepted socket not recieving events

The connected socket doesn't seem to be recieving any notifications of events, like when the client sends information, or shutdown the connection the connected socket on the server should recieve either FD_READ or FD_CLOSE which ever is appropriate but neither seems to happening.
DWORD WINAPI Network::MonitorEvents(void *ptr)
{
	WSAEVENT eventArray[EVENT_ARRAY_SIZE];
	int iEventCount = 0;
	SOCKET *sockListening = &network->sockListening;
	SOCKET *sockConnected = &network->sockConnected;
	int iReturn;
	bool *bContinue = &network->bContinue;
	int i;
	int iIndex;
	WSANETWORKEVENTS wsaNetEvents;
	int iSize;
	char szText[64];
 
	eventArray[iEventCount] = WSACreateEvent();
	if( eventArray[iEventCount] == WSA_INVALID_EVENT ){
		printf("WSACreateEvent error %d\n", WSAGetLastError() );
	}else{
		if( WSAEventSelect(*sockListening, eventArray[iEventCount], FD_ACCEPT | FD_CLOSE) == SOCKET_ERROR ){
			printf("WSAEventSelect error %d\n", WSAGetLastError() );
		}else{
			iEventCount++;
		}
	}
	
	while( *bContinue ){
		iReturn = WSAWaitForMultipleEvents(iEventCount, eventArray, FALSE, 5000, TRUE);
 
		if( iReturn == WSA_WAIT_IO_COMPLETION ){
			printf("WSA_WAIT_IO_COMPLETION...\n");
			continue;
		}else if( iReturn == WSA_WAIT_TIMEOUT ){
			printf("WSA_WAIT_TIMEOUT...\n");
			continue;
		}else if( iReturn == WSA_WAIT_FAILED ){
			printf("WSA_WAIT_FAILED... error %d\n", WSAGetLastError() );
			break;
		}else if( iReturn == WSA_WAIT_EVENT_0 ){
			iIndex = iReturn - WSA_WAIT_EVENT_0;
			
			if( iIndex == 0 ){
				WSAEnumNetworkEvents(*sockListening, eventArray[iIndex], &wsaNetEvents);
 
				if( wsaNetEvents.lNetworkEvents == FD_ACCEPT ){
					*sockConnected = accept( *sockListening, NULL, NULL);
					if( *sockConnected == INVALID_SOCKET ){
						printf("accept error %d\n", WSAGetLastError() );
					}
 
					eventArray[iEventCount] = WSACreateEvent();
					if( eventArray[iEventCount] == WSA_INVALID_EVENT ){
						printf("WSACreateEvent error %d\n", WSAGetLastError() );
					}else{
						if( WSAEventSelect(*sockConnected, eventArray[iEventCount], FD_READ | FD_CLOSE) == SOCKET_ERROR ){
							printf("WSAEventSelect error %d\n", WSAGetLastError() );
						}else{
							iEventCount++;
						}
					}
 
					printf("Client Connected\n");
				}else if( wsaNetEvents.lNetworkEvents == FD_CLOSE ){
					if( closesocket(*sockListening) == SOCKET_ERROR ){
						printf("closesocket error %d\n", WSAGetLastError() );
					}
					printf("Listening socket closed\n");
				}else if( wsaNetEvents.lNetworkEvents == FD_READ ){
					iSize = recv(*sockListening, szText, sizeof(szText), 0);
					if( iSize == SOCKET_ERROR ){
						printf("recv error %d\n", WSAGetLastError() );
					}else{
						printf(szText);
					}
				}
			}else if( iIndex == 1 ){
				WSAEnumNetworkEvents(*sockConnected, eventArray[iIndex], &wsaNetEvents);
 
				if( wsaNetEvents.lNetworkEvents == FD_READ ){
					iSize = recv(*sockConnected, szText, sizeof(szText), 0);
					if( iSize == SOCKET_ERROR ){
						printf("recv error %d\n", WSAGetLastError() );
					}else{
						printf(szText);
					}
				}else if( wsaNetEvents.lNetworkEvents == FD_CLOSE ){
					if( closesocket(*sockConnected) == SOCKET_ERROR ){
						printf("closesocket error %d\n", WSAGetLastError() );
					}
					printf("Connected socket closed\n");
				}
			}
		}
	}
 
	for(i = 0; i < iEventCount; i++){
		if( !WSACloseEvent( eventArray[i] ) ){
			printf("WSACloseEvent Error.\t\tError Code: %d\n", WSAGetLastError() );
		}
	}
	
	return 0;
}

Open in new window

shaun_hesterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

romanmCommented:
line 38: }else if( iReturn == WSA_WAIT_EVENT_0 ){
you only hit it when your listening socket has an event

it should be:
}else if( (iReturn >= WSA_WAIT_EVENT_0) && (iReturn < (WSA_WAIT_EVENT_0+iEventCount)) ){
so you get the index for any of the events
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shaun_hesterAuthor Commented:
I have been staring at this code for i don't know how long.  It's always the small things!!!
0
romanmCommented:
:) always good to have a second set of eyes
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.