Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two C++ applications A and B which communicate data together using boost-serialization and boost-asio libraries.
The communication is done for around 100 times from A to B and from B to A
The loop works like this:
A serialize some data to B
B make some tasks which take around 10 seconds
Once finished, B sends back some data to A
A makes some tasks which take around 2 seconds
Once finished, A sends some data again to B
and the loop repeated till some criteria is satisfied

The way i am using to synchronize the communication is static, i use wait function which block the application at each side while the other application is doing the tasks.
I would like to replace these wait by a reliable way.

Suggestions please?
Posted
Comments
KarstenK 17-Dec-13 6:22am    
named pipes or (local) network connection is possible. I also remember observing registry keys (???)
H.Brydon 17-Dec-13 8:14am    
If the two apps are always on the same machine, I'd suggest shared memory.
saephoed 6-Jan-14 16:03pm    
it really depends on what kind of apps the two are, if they could use the additional time for something else (maybe if they've go a UI which provides stuff which works independently of the communication) or have to (sync) wait anyway and of course if there's a chance for parallelisation.

I preffer Named Pipes.
Most of the time i do this to communicate from C# to C++ Applications.

Simple example for creating Pipe in C++:
C++
::CreateNamedPipe( PipeName, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, 0, 0, (DWORD)-1, &MySA );


Reading from Pipe is as easy as reading from file:

C++
HANDLE hPipe = CreateFile( _T("\\\\.\\pipe\\") + PipeName,  GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL , NULL ); 
CString Buffer;
if( hPipe != INVALID_HANDLE_VALUE )
{
	DWORD nNumRead;
	BOOL bTmp = ::ReadFile( hPipe, Buffer.GetBuffer(1024), 1024, &nNumRead, NULL );
	Buffer.ReleaseBuffer();
}


Sorry if the code don't machts 100% together.
I copyed the two code fragments out from two differend Projects.
But i think the principle is clear.
 
Share this answer
 
My advice would be to use Asynchronus Communication. For more details please see below link

Asynchronous communication[^]

Scalable ipc using asynchronous named pipes and IO completion ports/[^]
 
Share this answer
 
I'm going to go out on a limb and suggest program A spawn program B. On Windows, the parent process can obtain a wait handle that is signaled when the child process exits. Program A writes data to file, spawns program B with file name(s), and waits for B to exit.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900