Code/ServerApp/Source/ServerNetworking.cpp
//=================================================================================================
// Thread waiting on new Client Connection request
//=================================================================================================
Thread waiting on new Client Connection request
Thread waiting on new Client Connection request
void NetworkConnectRequest_Receive()
{	
	SOCKET ListenSocket = INVALID_SOCKET;
	std::thread(NetworkConnectRequest_Receive_UpdateListenSocket, &ListenSocket).detach();
	while( !gbShutdown )
	{
		if( ListenSocket != INVALID_SOCKET )
		{
			sockaddr	ClientAddress;
			int			Size(sizeof(ClientAddress));
			SOCKET		ClientSocket = accept(ListenSocket , &ClientAddress, &Size) ;
			if( ClientSocket != INVALID_SOCKET )
			{
				uint32_t freeIndex = ClientRemote::GetFreeIndex();
				if( freeIndex != ClientRemote::kInvalidClient )
				{
					char zPortBuffer[32];
					ClientRemote& newClient		= ClientRemote::Get(freeIndex);
					getnameinfo(&ClientAddress, sizeof(ClientAddress), newClient.mConnectHost, sizeof(newClient.mConnectHost), zPortBuffer, sizeof(zPortBuffer), NI_NUMERICSERV);
					newClient.mConnectPort		= atoi(zPortBuffer);
					newClient.mClientConfigID	= ClientConfig::kInvalidRuntimeID;
					NetworkConnectionNew(ClientSocket, &newClient);
				}
				else
					closesocket(ClientSocket);
			}
		}
		std::this_thread::yield();
	}	
}
void NetworkConnectRequest_Receive ( ) { SOCKET ListenSocket = INVALID_SOCKET ; std :: thread ( NetworkConnectRequest_Receive_UpdateListenSocket , & ListenSocket ) . detach ( ) ; while ( ! gbShutdown ) { if ( ListenSocket != INVALID_SOCKET ) { sockaddr ClientAddress ; int Size ( sizeof ( ClientAddress ) ) ; SOCKET ClientSocket = accept ( ListenSocket , & ClientAddress , & Size ) ; if ( ClientSocket != INVALID_SOCKET ) { uint32_t freeIndex = ClientRemote :: GetFreeIndex ( ) ; if ( freeIndex != ClientRemote :: kInvalidClient ) { char zPortBuffer [ 32 ] ; ClientRemote & newClient = ClientRemote :: Get ( freeIndex ) ; getnameinfo ( & ClientAddress , sizeof ( ClientAddress ) , newClient . mConnectHost , sizeof ( newClient . mConnectHost ) , zPortBuffer , sizeof ( zPortBuffer ) , NI_NUMERICSERV ) ; newClient . mConnectPort = atoi ( zPortBuffer ) ; newClient . mClientConfigID = ClientConfig :: kInvalidRuntimeID ; NetworkConnectionNew ( ClientSocket , & newClient ) ; } else closesocket ( ClientSocket ) ; } } std :: this_thread :: yield ( ) ; } }
Thread waiting on new Client Connection request
Thread waiting on new Client Connection request
// Detect connection request from Clients