Code/ServerApp/Source/Application.cpp
//=================================================================================================
// NETIMGUI NAMEDPIPE RECEIVE MESSAGE
// Receive Client connection information from another running application and 
// keep the config to attempt connexion to it later
//=================================================================================================
NETIMGUI NAMEDPIPE RECEIVE MESSAGE
Receive Client connection information from another running application and
keep the config to attempt connexion to it later
NETIMGUI NAMEDPIPE RECEIVE MESSAGE Receive Client connection information from another running application and keep the config to attempt connexion to it later
void NetImguiNamedPipeMsgReceive( HANDLE& hNamedPipe )
{
	char ComPipeBuffer[256];
	DWORD cbBytesRead(0);
	if (hNamedPipe == INVALID_HANDLE_VALUE)
	{
		hNamedPipe = CreateNamedPipeA(kServerNamedPipe,
			PIPE_ACCESS_INBOUND | FILE_FLAG_FIRST_PIPE_INSTANCE,
			PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_NOWAIT,
			1, 0, sizeof(ComPipeBuffer), 0, nullptr);
	}
	if( ReadFile(hNamedPipe, ComPipeBuffer, sizeof(ComPipeBuffer) - 1, &cbBytesRead, nullptr) )
	{
		DWORD cbBytesReadTotal(cbBytesRead);
		while(	cbBytesReadTotal < sizeof(ComPipeBuffer)-1 && 
				ReadFile(hNamedPipe, &ComPipeBuffer[cbBytesReadTotal], sizeof(ComPipeBuffer) - cbBytesReadTotal - 1, &cbBytesRead, nullptr) )
			cbBytesReadTotal += cbBytesRead;
		ComPipeBuffer[cbBytesReadTotal] = 0;
		ClientConfig cmdlineClient;
		if (InitClientConfigFromString(ComPipeBuffer, cmdlineClient))
			ClientConfig::SetConfig(cmdlineClient);
		CloseHandle(hNamedPipe); 
		hNamedPipe = INVALID_HANDLE_VALUE;
	}
}
void NetImguiNamedPipeMsgReceive ( HANDLE & hNamedPipe ) { char ComPipeBuffer [ 256 ] ; DWORD cbBytesRead ( 0 ) ; if ( hNamedPipe == INVALID_HANDLE_VALUE ) { hNamedPipe = CreateNamedPipeA ( kServerNamedPipe , PIPE_ACCESS_INBOUND | FILE_FLAG_FIRST_PIPE_INSTANCE , PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_NOWAIT , 1 , 0 , sizeof ( ComPipeBuffer ) , 0 , nullptr ) ; } if ( ReadFile ( hNamedPipe , ComPipeBuffer , sizeof ( ComPipeBuffer ) - 1 , & cbBytesRead , nullptr ) ) { DWORD cbBytesReadTotal ( cbBytesRead ) ; while ( cbBytesReadTotal < sizeof ( ComPipeBuffer ) - 1 && ReadFile ( hNamedPipe , & ComPipeBuffer [ cbBytesReadTotal ] , sizeof ( ComPipeBuffer ) - cbBytesReadTotal - 1 , & cbBytesRead , nullptr ) ) cbBytesReadTotal += cbBytesRead ; ComPipeBuffer [ cbBytesReadTotal ] = 0 ; ClientConfig cmdlineClient ; if ( InitClientConfigFromString ( ComPipeBuffer , cmdlineClient ) ) ClientConfig :: SetConfig ( cmdlineClient ) ; CloseHandle ( hNamedPipe ) ; hNamedPipe = INVALID_HANDLE_VALUE ; } }
NETIMGUI NAMEDPIPE RECEIVE MESSAGE
Receive Client connection information from another running application and
keep the config to attempt connexion to it later
NETIMGUI NAMEDPIPE RECEIVE MESSAGE Receive Client connection information from another running application and keep the config to attempt connexion to it later
// Interprocess NamedPipe not opened for communications yet, create it // See if there's new data waiting for us // Someone sent something, read entire data stream // Will recreate the pipe, since it seems only 1 per remote application can exist