Interprocess communication

Started by
4 comments, last by Blednik 15 years, 3 months ago
Heya. I am looking for a way to have two processes communicate to each other in Windows XP, but I am uncertain which path to use as there seem to be many methods for IPC. I've been leaning toward named pipes, but the documentation online is rather scarce and incomplete. There are only two processes in the plan (both written in C++), one of them being windowless. The GUI process should be able to control the windowless one using IPC and they'll need to transfer over certain commands and small bits of data to each other. Any suggestions?
Advertisement
*bump*

This is as far as I managed to get with named pipes.
http://www.codeguru.com/forum/showthread.php?t=468573
look into the CreateProcess() win32 function, or the boost i/o libraries
--------------------------------------Not All Martyrs See Divinity, But At Least You Tried
Well, there are many other ways to do IPC. I just looked at a friend's code which used named pipes and it's just horrible to communicate that way. You may want to look into several other ways to implement IPC:

http://zeroc.com/ice.html
http://www.codeproject.com/KB/IP/cnamedpipe.aspx (This one is just a wrapper for the Win32 api functions, it is old, but could be worth a look, if only to see how it's done)

About the problems you mentioned on codeguru. Maybe we can help if you post the relevant code in this forums (and/or their's as well), so we can try to determine what's going wrong.
Can you give us a high level overview of what the two processes are doing?

Does the GUI process create or spawn the windowless one, or vice versa? Or can the windowless one run in complete isolation?

Towards the future, would the ability to connect the GUI to a remote computer running the other process be desired?

The "best choice" depends on quite a number of factors, of which you have only really described the data flow.
I've taken an interest in named pipes because of a recommendation from a more experiended coder. Both, the server and client should only run on a local computer i.e. there is no need for a remote connection.
The GUI application (the server) spawns the windowless client on request. The client then attempts to connect to the server and begins the data exchange. Should the connection fail (e.g. server is absent), the client automatically terminates. The client cannot run on its own and it relies on the server for commands. This is merely the concept of the final application and I am currently in the state to get the IPC going.
Please note that the following code is only a prototype for the IPC part. Just split it into files and you should be able to compile it. You have to execute the server.exe and then the client.exe manually.

Server: http://pastebin.com/m683c29b1
Client: http://pastebin.com/m5e95d9eb

I've managed to get the data to flow in one direction at a time by commenting out certain write/read parts of the code, but both applications freeze when trying to read and write to the pipe on both sides (server and client-side) at the same time.

This topic is closed to new replies.

Advertisement