Code/ServerApp/Source/ServerNetworking.cpp
//=================================================================================================
// Receive every commands sent by remote client and process them
// We keep receiving until we detect a ping command (signal end of commands)
//=================================================================================================
Receive every commands sent by remote client and process them
We keep receiving until we detect a ping command (signal end of commands)
Receive every commands sent by remote client and process them We keep receiving until we detect a ping command ( signal end of commands )
bool Communications_Incoming(SOCKET Socket, ClientRemote* pClient)
{
	bool bOk(true);
	bool bPingReceived(false);
	NetImgui::Internal::CmdHeader cmdHeader;
	while( bOk && !bPingReceived )
	{	
		uint8_t* pCmdData	= nullptr;
		int sizeRead	= recv(Socket, reinterpret_cast<char*>(&cmdHeader), sizeof(cmdHeader), MSG_WAITALL);
		bOk				= sizeRead == sizeof(cmdHeader);
		if( bOk && cmdHeader.mSize > sizeof(cmdHeader) )
		{
			pCmdData													= NetImgui::Internal::netImguiSizedNew<uint8_t>(cmdHeader.mSize);
			*reinterpret_cast<NetImgui::Internal::CmdHeader*>(pCmdData) = cmdHeader;
			const int sizeToRead										= static_cast<int>(cmdHeader.mSize - sizeof(cmdHeader));
			sizeRead													= recv(Socket, reinterpret_cast<char*>(&pCmdData[sizeof(cmdHeader)]), sizeToRead, MSG_WAITALL);
			bOk															= sizeRead == sizeToRead;
		}
		if( bOk )
		{
			switch( cmdHeader.mType )
			{
			case NetImgui::Internal::CmdHeader::eCommands::Ping:		bPingReceived = true; break;
			case NetImgui::Internal::CmdHeader::eCommands::Disconnect:	bOk = false; break;
			case NetImgui::Internal::CmdHeader::eCommands::Texture:		Communications_Incoming_CmdTexture(pClient, pCmdData);		break;
			case NetImgui::Internal::CmdHeader::eCommands::DrawFrame:	Communications_Incoming_CmdDrawFrame(pClient, pCmdData);	break;
			case NetImgui::Internal::CmdHeader::eCommands::Invalid:
			case NetImgui::Internal::CmdHeader::eCommands::Version:
			case NetImgui::Internal::CmdHeader::eCommands::Input:		break;
			}
		}
		NetImgui::Internal::netImguiDeleteSafe(pCmdData);
	}
	return bOk;
}
bool Communications_Incoming ( SOCKET Socket , ClientRemote * pClient ) { bool bOk ( true ) ; bool bPingReceived ( false ) ; NetImgui :: Internal :: CmdHeader cmdHeader ; while ( bOk && ! bPingReceived ) { uint8_t * pCmdData = nullptr ; int sizeRead = recv ( Socket , reinterpret_cast < char * > ( & cmdHeader ) , sizeof ( cmdHeader ) , MSG_WAITALL ) ; bOk = sizeRead == sizeof ( cmdHeader ) ; if ( bOk && cmdHeader . mSize > sizeof ( cmdHeader ) ) { pCmdData = NetImgui :: Internal :: netImguiSizedNew < uint8_t > ( cmdHeader . mSize ) ; * reinterpret_cast < NetImgui :: Internal :: CmdHeader * > ( pCmdData ) = cmdHeader ; const int sizeToRead = static_cast < int > ( cmdHeader . mSize - sizeof ( cmdHeader ) ) ; sizeRead = recv ( Socket , reinterpret_cast < char * > ( & pCmdData [ sizeof ( cmdHeader ) ] ) , sizeToRead , MSG_WAITALL ) ; bOk = sizeRead == sizeToRead ; } if ( bOk ) { switch ( cmdHeader . mType ) { case NetImgui :: Internal :: CmdHeader :: eCommands :: Ping : bPingReceived = true ; break ; case NetImgui :: Internal :: CmdHeader :: eCommands :: Disconnect : bOk = false ; break ; case NetImgui :: Internal :: CmdHeader :: eCommands :: Texture : Communications_Incoming_CmdTexture ( pClient , pCmdData ) ; break ; case NetImgui :: Internal :: CmdHeader :: eCommands :: DrawFrame : Communications_Incoming_CmdDrawFrame ( pClient , pCmdData ) ; break ; case NetImgui :: Internal :: CmdHeader :: eCommands :: Invalid : case NetImgui :: Internal :: CmdHeader :: eCommands :: Version : case NetImgui :: Internal :: CmdHeader :: eCommands :: Input : break ; } } NetImgui :: Internal :: netImguiDeleteSafe ( pCmdData ) ; } return bOk ; }
Receive every commands sent by remote client and process them
We keep receiving until we detect a ping command (signal end of commands)
Receive every commands sent by remote client and process them We keep receiving until we detect a ping command ( signal end of commands )
//--------------------------------------------------------------------- // Receive all of the data from client,  // and allocate memory to receive it if needed //--------------------------------------------------------------------- //--------------------------------------------------------------------- // Process the command type //--------------------------------------------------------------------- // Commands not received in main loop, by Server