data transfer

S

socket

Hey,

I need to make two programs I wrote to communicate with each other,
but what's the best way to implement it? Both programs will be running
on the same machine.
I don't want to open sockets and transfer the data 'network style'
because of security issues.

The data transfer is only one way, program A will be sending streams
of data to program B, and program B will output the data.

I thought about using shared memory between the two applications but
how can I make program B to read from memory when program A updates
the allocated memory?

If you have a better idea I'd love to hear it :)
I'm using gcc.
 
R

Richard Heathfield

socket said:
Hey,

I need to make two programs I wrote to communicate with each other,
but what's the best way to implement it? Both programs will be running
on the same machine.
I don't want to open sockets and transfer the data 'network style'
because of security issues.

If the programs are on the same machine, there are no security issues. Just
yank the wire out of the wall, and your security problems are solved.

The ISO C answer is: use the file system. For a whizzier bangier answer, ask
in a newsgroup devoted to your platform; comp.unix.programmer,
comp.os.linux.development.apps, comp.os.ms-windows.programmer.win32, or
whatever.
 
G

Gordon Burditt

I need to make two programs I wrote to communicate with each other,
but what's the best way to implement it? Both programs will be running
on the same machine.
I don't want to open sockets and transfer the data 'network style'
because of security issues.

Then you'd better state the security issues in excruciating detail,
if you're worried about communications between two programs on the
same machine being snooped on. What the heck *CAN* you trust?
If you can't trust all the people with administrative privileges
on that machine you need to find another machine.

One possible way is to pipe data from one program (outputs via
stdout) to the other (reads stdin). How you set up the plumbing
is outside the scope of C but it can be done easily in UNIX shell
syntax. (But guess how that gets implemented on many BSD UNIX
systems? A pair of sockets.) You could also have one program write
into a file and the other one reads it (this is how MS-DOS faked
pipes, and a reasonable way to get around not having real support
for pipes) (and something else can read the file also - security
problem). Another way is to compile the two programs together and
have one call the other. Guess what you can do with a debugger?
Security problem. Another possibility is shared memory, which
requires non-standard functions (such as mmap() or the shm* functions).
Shared memory can be shared by more than two programs. Security
problem.
The data transfer is only one way, program A will be sending streams
of data to program B, and program B will output the data.

This description of the data flow begs for a pipe, if your OS
supports it.
I thought about using shared memory between the two applications but
how can I make program B to read from memory when program A updates
the allocated memory?

You won't find much in C that will help you synchronize two programs
using a shared memory segment to avoid problems such as reading the
data before it's written, or busy waiting (very inefficient on a
multi-tasking system), or deadlock.

Gordon L. Burditt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,102
Messages
2,570,645
Members
47,247
Latest member
GabrieleL2

Latest Threads

Top