Click to See Complete Forum and Search --> : Communication between Java and C++


cy163
April 18th, 2008, 09:28 AM
Hi All.

I am working on a project in which two machines are used. One machine is used as front-end machine, the other is used as back-end machine.

The front-end machine is responsible to receive data from the user and to forward the data to the backend machine. The backend machine is responsible to processing the data and return the result to the frontend machine. In turn , the frontend machine forwards the result to the user.

Both the frontend and backend machines run Linux. The data processing program (a legency system) on the backend machine is writtern in C++.

Moreover, to facilitate the data submission, the system allows the user to visit a web page on the frontend in order to fill out and submit a form to the frontend machine. To implement this goal, currently i am going to use JSP to create a web page to collect data from the user and accordingly use Java/JavaBean to move data to and from the backend machine.

However, i am not sure whether the above idea is correct or not. If it is feasible, then how to implement the communication between C++ (programming langauge used in backend machine) and Java (programming language used in frontend machine). Or, I should use C++ in the frontend machine too. Or I should use web service technology in the frontend.
Or SOCKET technology?



I would appreciate any help here

ProgramThis
April 18th, 2008, 09:33 AM
A quick search on Google found many (http://www.javaworld.com/javaworld/javatips/jw-javatip17.html) examples of how to access C++ code within Java. There is a package called JNI (http://java.sun.com/j2se/1.5.0/docs/guide/jni/index.html) that allows such interaction.

dlorde
April 18th, 2008, 01:51 PM
If the front-end machine is just forwarding data to the back-end machine, the simplest solution would be to use a language-neutral data format for the exchange (e.g. XML messaging). This way the front-end and back-end would be decoupled in terms of langage.

We are all shaped by the tools we use, in particular: the formalisms we use shape our thinking habits, for better or for worse, and that means that we have to be very careful in the choice of what we learn and teach, for unlearning is not really possible...
E. Dijkstra

cy163
April 19th, 2008, 08:34 AM
If the front-end machine is just forwarding data to the back-end machine, the simplest solution would be to use a language-neutral data format for the exchange (e.g. XML messaging). This way the front-end and back-end would be decoupled in terms of langage.

We are all shaped by the tools we use, in particular: the formalisms we use shape our thinking habits, for better or for worse, and that means that we have to be very careful in the choice of what we learn and teach, for unlearning is not really possible...
E. Dijkstra


Thanks for your posting. Using xml as data format can save much effort translating between data in different format. However, could you suggest me appropriate method for moving the data to and from front- and back-end machine. Someone told me to use SOCKET technique. Is SOCKET feasible for this scenario. Or there is better method.

dlorde
April 19th, 2008, 08:46 AM
Sockets would be good - have a read of this description: About Sockets (http://java.sun.com/docs/books/tutorial/networking/sockets/index.html), and decide if they suit what you want to do.

A complex system that works in invariably found to have evolved from a simple system that worked...
J. Gall