Communication between a java and c++ program


 
Thread Tools Search this Thread
Top Forums Programming Communication between a java and c++ program
# 1  
Old 11-13-2001
Communication between a java and c++ program

Hi,

I have the following problem. I have 2 programs, a java program and a c++ program. These 2 programs have to communicate with each other in full duplex mode. I want to use pipes for this communication. So when the c++ program pust something on the stdout the java program must be able to read this and the other way around. Can, or is it wise to use pipes for doing this and if it isn't, what other options do I have?

thx in advance,

lmnt22
# 2  
Old 11-13-2001
Try running the c program over jni (java native interface)
assuming you have the c++ program source code
over jni methods you can put the other language directly into your java program and define interfaces so there is no need to go over stdout etc

-hope this helps- :-)
# 3  
Old 11-13-2001
From your question, I assume you have 2
separate programs (1 java and 1 c++) and have
the source code for these programs. I also
assume that each of these programs reads stdin
for it's data and writes data to stdout.

I also assume that these programs have no
relationship to each other meaning that one
program does not start the other as a child.

If you want to use pipes, you may want to
consider FIFO devices (sometimes referred to
as a "named" pipe). You can create FIFO's
using the "mknode" command. If you want you
programs to utilize stdin and stdout, for example:

myjavaprog < /dev/myfifo1 > /dev/myfifo2 &
myc++prog < /dev/myfifo2 > /dev/myfifo1

then your code should first close all open
file descriptors and open /dev/myfifo1 and
/dev/myfifo2 for reading or writing as
appropriate. Also, you should open a file
for error output as well. Once you've done this,
the programs should work as if stdin and stdout
have been redirected. The main caveat here is that
you can expierence deadlock if your programs
block on reading or writing as reading and empty
pipe will wait forever and writing a full pipe
will block forever unless you set up your
connections as non-blocking. There are actually
a number of ways to deal with this but it does
require some forthought.

I hope this helps a bit. Smilie
# 4  
Old 11-13-2001
Thx guys,

I discussed both methods with my collegue and we didn't choose any of both methods. One of the issues is that both programs have to be portable to almost any system. We don't realy know if windows pipe handling is the same as unix pipe handling. It pipes isn't an option. (I only found this out after I wrote the topic)

Considering the small amount of time we have to complete the project we decided to implement some messeging system, which is indipendent of the method u use for in/output. For now we use 2 temp files which for each program (there are indeed 2 programs, a java program and a c program). But it might be possible to use pipes or sockets in the future. An advantage is that there doesn't have to be send much data between the 2 programs.(java is the gui and the c++ program handles the openGL drawing and heavy calculations).

So we use temporary files. However I would like to thank you for your fast response!

lmnt22
# 5  
Old 11-13-2001
Portability to Windoze is a very significant
addition to your orignally stated problem
however, you still have some options.
Here's an interesting article on Linux and Win2K
pipes...

http://www-106.ibm.com/developerwork...,l=805,p=pipes

...and from MS...

http://msdn.microsoft.com/library/de...pipes_2vqr.asp

...it may give you more ideas and options.

Personally, I would recommend sockets.
Enjoy Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

java compile and run program help

What is the trick to get a java program to run and compile? I can't even get a basic skeleton to run and compile. What packages do I need? I figured the java-gcj and gcc-java packages was enough. Do I need any other packages? I thought I had to do this and it would work but its not. javac... (1 Reply)
Discussion started by: cokedude
1 Replies

2. Programming

Program java arguments

Hello, The arguments are strings. In my code I need them to be a different type, I do the cast but it is not feasible ... Have you any idea? Thank you (8 Replies)
Discussion started by: chercheur857
8 Replies

3. Shell Programming and Scripting

communication between shell and and a demon 'c' program

Hello, i have a demon 'c' program that have a dynamic table of logic registers ( 2000 variables ). exemple of registers: I1.34.5 M23.4.1 I want from shell acess to this table of registers. How can i do this? with something like for read I1.34.5: #cat... (3 Replies)
Discussion started by: rzyz
3 Replies

4. Programming

need logic for java program

Hi All, I need to to wright a java programm for the following query. Qus: output need to genarate a number+ alphnumric sequence in java and get converted into ASCII code so that i can use mod logic on that. example Output: like 10 digit number 1AAAAAAAAA 1AAAAAAAAB 1AAAAAAAAC . .... (4 Replies)
Discussion started by: Ganesh Khandare
4 Replies

5. Programming

C++/Java full-duplex communication

Hello, here's my situation: I have a C++ server running on a well known machine and a number of Java clients running on other machines (assumed as unknown) on the same LAN. What I want to achieve is full duplex communication between those applications, in order to exchange complex objects and data... (3 Replies)
Discussion started by: demerzel3
3 Replies

6. Shell Programming and Scripting

Executing a Java Program

I am entirely new to shell scripting and would like to create a script to execute a java program called Main. I've already compiled it and placed the .java and .class files at /root/javaTest. Next I made a shell script that simply contained: java /root/javaTest/Main . I made the script... (2 Replies)
Discussion started by: hypnotic_meat
2 Replies

7. UNIX for Dummies Questions & Answers

using a variable from java program in unix

Hi, I need to execute a java program in a shell script.I then need to assign the value being returned by the program into a unix variable.Is there any way i can access the value in a variable in java program? As in if my java code has a variable, . . . . valueA =x.getValue() ..... can... (1 Reply)
Discussion started by: inquisitive101
1 Replies

8. Programming

C program using IPC (inter process communication)

i want to write a C chat program that communicates over IPC(inter process communication), that could be run using 2 seperate terminal windows within the same computer. so that wat u type in one terminal window , should appear on the other and vice versa... could some one please help me with the... (2 Replies)
Discussion started by: localp
2 Replies

9. Shell Programming and Scripting

how can i run java program from any where

Hello all sorry didnt know where to post it i compiled simple program that using "System.getProperty("user.dir");" now i compiled the program under directory foo and and its running great when i do "java myapp" i included this directory in the $PATH env variable so i could see it fro any where... (1 Reply)
Discussion started by: umen
1 Replies

10. UNIX for Dummies Questions & Answers

executing the su command from a java program.

Say in unix (AIX) m/c, I am logged in with s1 user and want to start process p1 with user credentials of s2. I can do manually in this way: #su - s2 #enter password for s2> somePassword $ p1 But all this I have to do through a java program. How to pass the password through program. One... (1 Reply)
Discussion started by: shailendrat
1 Replies
Login or Register to Ask a Question