Inter-process communication...

Started by
8 comments, last by MaulingMonkey 21 years, 7 months ago
I''m a lurker to these forums, and am currently learning C++. I know all the basic syntax, have done some OpenGL, some MFC, some VCL...I''ve used a bunch of libraries, but what I''m trying to learn right now is how to do inter-process communications. The program im working on will be released on multiple platforms... so whatever I used has to be compatible with the major OSes (Windows, Linux, Macs...) or I need to know about something for each that I can use to create a wrapper class that works for them all. I''ve looked at the COM interface for windows, and it looks like, well, a big hideous overbloaded monster . I dont want something extreemly complex to use...this is my hobby, LATER it will be my job (I''m half a month shy of 17). Pretty much I''m going to have a server/client interface, with 1, single threaded server. Clients should hopefully be able to write data very fast to the server''s memory space (as it will be dealing with graphic operations). The client shouldn''t need to read much from the server. Links to articles would be welcomed, or libraries, or anything else that might help me out. Thanks! -Mike
Advertisement
look into using SDL, Opengl / GLUT.

Its my duty, to please that booty ! - John Shaft
IPC? Just use network sockets. If you stick to BSD sockets-compatible implementations/functions, then you''re portable to most platforms.
pipes.
there part of the CRT, look into them ..
kinda lacking examples, but enough doco to work with.
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
jwalker: Checked out SDL, it looked promising but I couldn''t find anything describing how to USE pipes under it...as for OpenGL/GLUT, im allready using that...IPC is what I''m wondering about.

Oluseyi: Alas, I have yet to do network programming by hand (I''ve used VCL using C++ Builder, but that hardly counts as it does almost everything for you, but then it links in DLLs so bye bye compatability...not to mention I dont need any other VCL data...). I do have a good sockets book, but it''s *nix specific. And since I''m programming on a Win machine, and dont want to learn the (apparently) huge and confusing SOCKS interface at the moment, my only option is the bloated VCL libs.

silvermace: That''s what I''ve decided to use...pipes that is. C++ Builder seems to have docs explaining it well enough for me to understand...

which leaves me with one question that needs solving...

read blocks if no data is in que to read. This server needs to continue to do other tasks...is there any way to test to see if there''s new data ready to read from the pipe? I have a simple loop in my test program like so:

while (!(kbhit() && (getch() == 27))) //If user presses ESC, quit
{
if (read(handles[PIPE_IN],&buffer,256)) //If data is read...
{
cprintf("Recieved message: %s\n\r",buffer); //Print it out.
}
}

Read will block and ESC wont quit untill a message is sent first, and that wouldn''t be good. At worst, I could program a subprogram that would send ''null'' messages to keep it from stalling, but I''m wondering if anyone knows a more...ellegant way. I''d probably have to program something like this:

while (!(kbhit() && (getch() == 27))) //Loop till ESC
{
if (dataavailable(handles[0][PIPE_IN])) //Data avail? If so..
{
read(handles[PIPE_IN],&buffer,256); //Read it, and
cprintf("Recieved message: %s\n\r",buffer); // print it out.
}
}

only problem is I dont know the equivilant of dataavailable....

the other soulution is if there''s a parameter I can set when using the _pipe function for read to not block...(O_NOBLOCK ?), but again I don''t know what that parameter would be.

the third soulution is multithreading...0.0.

All help will be appreciated!
Thanks for the comments allready made
-Mike
Once you answer the last question, another pops up . I solved the blocking by having the program send itself a unique ''null'' string using pipes. Only problem is that other programs couldn''t send data TO this program unless I spawned them using spawnl from within the program. Now the program I''m working on should hopefully be quite able of spawning everything, but I''m curious if there''s a way to share a pipe handle somehow between programs. I guess this really would apply to any type of handle. Even to have spawned programs be able to access the pipe handle, I had to include fileinfo.obj in my project using C++ Builder... so it''s obvious programs normally dont share their handles.

To re-itterate, HOW DO YOU SHARE PIPE HANDLES WITH OTHER PROGRAMS?

im using the std headers that came with C++ builder...
fnctl.h for _pipe(int *__phandles, unsigned int __psize, int __textmode)

io.h for write(int __handle, const void *__buf, unsigned int __len)

and read(int __handle, const void *__buf, unsigned int len)

Thanks!
-Mike
quote:Original post by MaulingMonkey
To re-itterate, HOW DO YOU SHARE PIPE HANDLES WITH OTHER PROGRAMS?

I don't think you can with a pipe. (Hence, the word "pipe".) You'll have to create a seperate pipe for each client, and "poll" each pipe continously. A more efficient way is to create a seperate thread and pipe for each client.

If you don't want to create multiple pipes, another idea is to use a UDP socket. A UDP socket is a "connectionless" socket. This allows multiple clients to write to it. In contrast, a normal TCP socket allows only one client per socket. However, TCP has alot of other features. For instance, it makes sure packets get to their destination, and in the correct order. UDP sends packets blindly. This may not be a problem for you, since your client and server are running on the same machine.

I know you said you didn't want to learn sockets, but there are a million cookbook tutorials out there. BSD sockets are fairly portable. Your Windows sockets (AKA WinSock) will work on UNIX, and your UNIX sockets book is applicable to Windows. You just have to add a WSAStartup and WSACleanup call to your Windows code.


[edited by - poozer on September 4, 2002 1:48:19 AM]
You could use a shared memory/event system, where you signal an event everytime the shared memory data is updated. Then you could access the data with any application on the system. Just a thought.

Kevin "Khawk" Hawkins
CEO and News Director, GameDev.net
Software Engineer, Raydon Corporation
Author, OpenGL Game Programming
Developer Diary

Admin for GameDev.net.

Under windows, try looking into memory-mapped files.

------------------------------
BASIC programmers don''t die, they just GOSUB and don''t return.
------------------------------BASIC programmers don't die, they just GOSUB and don't return.
For basic Win32 & *Nix cross platform socket info and sample source see: Internet Programming Crash Course.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man

This topic is closed to new replies.

Advertisement