473,320 Members | 1,993 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Communication between a Java and a C application

4
Hi

I have a java application that runs a C application native code(exe file) as a proccess. I need to communicate with this C application and stop it's method, get a data out of it then change it in java application and send back the new data to the C application to continue the proccess. I am thinking about pipe or socket.
Fist I dont know how to comunicate to a exe file and Second what is the most simple and fast way to do it?
Sep 9 '09 #1
6 5687
JosAH
11,448 Expert 8TB
@golabi
If that C application doesn't open a communication socket you can forget that alternative; you have to communicate through ordinary input and output streams, in particular stdin and stdout (in C terminology). Read the API documentation of the Process class.

If that C application doesn't even do that you have to forget any form of communication between the two applications.

kind regards,

Jos
Sep 9 '09 #2
golabi
4
Thanks Jos for your quick respond

Actually I am quite new in C . Actually I have the C application source code and I should change it to be able to communicate. Is it right to make an exe file after changing C application to be able to open a socket or ordinary input output stream,
and then use this exe file in java application?
Sep 9 '09 #3
JosAH
11,448 Expert 8TB
@golabi
Yep, if you can change the C source code you can make it open a socket for communication. The Java application would send commands and receive the results through that socket. If can even make that C application quit by issuing the correct command. Your C application turns into a small server so to speak and your Java application will be its client.

Otherwise, if you hate sockets or are allergic to them ;-) you can issue commands through the C application's input stream (stdin) and it can send the results through its output stream (stdout). The Java application can write to C's input stream and read from its output stream. Again, read the API documentation for the Process class.

kind regards,

Jos
Sep 9 '09 #4
golabi
4
Thanks so much for the elaborated answer
Sep 9 '09 #5
golabi
4
I will appreciate if anyone answers my question because I still have problems. I decided to use stdin and stdout. I created a child process in java to run the C application and using getInputStream and getoutputStream in 2 different threads but it hangs maybe it because both treads are working with the same files and if I synchronize it dead lock will happen.
So I thought I should write the output of C into a file and read it by java then change it and send it back in the same way. But still I dont know How can I stop the running C process to listen to the java and get its input from the java application????
Sep 11 '09 #6
JosAH
11,448 Expert 8TB
There are quite some pitfalls with running an external process you have to be aware of; read this article; it explains how to circumvent them.

kind regards,

Jos
Sep 11 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: JW | last post by:
Hi, I am trying to see if I can display an animated .gif file on a Java application (that is, I do not want to have to show a series of static images to simulate animateion; I just want to...
2
by: Generic Usenet Account | last post by:
I am trying to create a Java application that reads a list of URLs from a file and stores their contents on the local file system. I have succeeded in accessing normal websites, but I am unable to...
13
by: Charles Handy | last post by:
How does FastCGI compare against java Apps running in java app servers like TomCat, Sun One, WebLogic and WebSphere? Is there a business case for switching from CGI to Java? Performance?...
2
by: Begoña | last post by:
in my java application I've made a call to this stored procedure CREATE procedure pruebaICM @pANI varchar(20), @pTABLA varchar(20), @pInsert varchar(500), @pUpdate varchar(1000), @pFLAG...
2
Saghar
by: Saghar | last post by:
Hi, Could somebody help me about this topic? I want to know how we can call and execute a non-java source file in a java application. For example, a simple Java application is run, there is an...
8
by: Ananthu | last post by:
Hi I have done all the codings part for connecting mysql with java in eclipse environment. Coding Part: import java.sql.Connection; import java.sql.DriverManager; public class...
4
by: MimiMi | last post by:
I want an application written in C# to start an application written in java and be able to communicate with each other. I believe one way to do this is to use socket programming, having the java...
1
by: zgh1970 | last post by:
I did a test on running db2 database java code on 32-bit and 64-bit db2 instance. It seams that java application with 32-bit JVM couldn't run at 64-bit db2 instance. Also 64-bit JVM couldn't run...
0
by: yatinbvn | last post by:
hi hello friends i find that if we want publish our application to Nokia ovi store we must verified our java application from one of the CA(javaverified.com,verisign,thawate etc...) i need...
2
by: Stefan Olsson | last post by:
Hello Windows 7, latest Java installed. I have two jar files, on with the main class included which uses classes in the other java class. The two jar file names are swt.jar (contain...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.