• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Pipe between Java and C processes?

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody!
I never had the chance to use pipes in Java so I'm a newbie in this field. I know from C that pipes can be used to communicate between 2 separate processes.
When reading about this in Java I see two different definitions:
1. that a pipe can be used ONLY to communicate between threads in the same JVM.
2. a pipe can be used to communicate with another process as long as the pipe is not created by Java.
Which one is it? I would need this to communicate between a Java process and a C process.
Thanks!
Cristian
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Java Pipe classes are implemented in-memory, so they will only work within the same JVM:

Instead of streaming data to a file, a thread can stream it through a pipe to another thread. The first thread writes to the
pipe, and the second thread reads from the pipe. A pipe is neither a file nor a network connection, but a structure in memory that holds the data that is written until it is read.



Java Thread Programming by Paul Hyde page 141

It may be possible to use named pipes outside the VM (see here), but I've never seen anyone do it.

 
Cristian Vrabie
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!
I will try the solution for named pipes outside VM and post my findings.
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On one side put




getInputStream() .. MyInputStreamClassExtension : extend class InputStream or anything that extends it.
 
Cristian Vrabie
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I managed to do this work by making the C program create the pipe, then opening it from Java as a normal file. Pretty easy actually.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic