0

Possible Duplicate:
fastest (low latency) method for Inter Process Communication between Java and C/C++

I want to ask if anyone could suggest me the fastest way to transfer high amounts of data between two processes on the same machine one built in Java and other in C++

I have to build a business application having a client-server architecture over internet which has a structure like this->

Java Client App ---( Java Sockets )----- > Java Servlet---- > C++ Business Logic.

It needs to be highly portable as we can't say beforehand the target environment of the client, so java will be the best choice for it according to me. It will be interacting with the java servelet through java sockets. The servelet should be interacting with the business logic built in C++.

I will be using java just for the communication part and all the rest of the business logic will be there in C++.

I am an amateur programmer in Java and have a good level of experience in C++.

Any kind of suggestion would be welcomed..

Community
  • 1
  • 1
  • For what it's worth - a socket is a construct provided by operating systems implementing the tcp/ip protocol; calling something a "java socket" is slightly inaccurate. Java has an API for using TCP/IP sockets, just as most C/C++ implementations have a library for using those same sockets. This is just by way of saying that the languages are not significant here, and if you really meant "Java socket", I thought you may have mistaken them for language-specific items. – arcy Dec 29 '12 at 15:55

1 Answers1

7

I would use a Socket over loopback on the assumption that the volume of data doesn't need be more than you get from Client App or return to it and latency doesn't need to be many times smaller.

Using a Socket is the most portable and if you have to run these on different machines you can.

With Java you can get a few Gb/sec with latencies below 10 micro-seconds over a Socket.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • When you consider to add even more, even diverse, components later, you could go the Service-oriented Architecture (SOA) route and implement such socket-based interfaces between programs as SOAP web services. But when you are sure that you will never have more than these two applications and that you will never need any more interoperability, this would fall into the YAGNI department. – Philipp Dec 29 '12 at 15:18
  • @peter do you have any examples for this? It will be very helpful for me. – GNK Jul 15 '22 at 09:09
  • @GNK there are so many options it's hard to know where to start. What are you trying to do? – Peter Lawrey Jul 17 '22 at 06:51
  • Thank you for your reply. I have a test application in that java and C++ code and all code together in the same android JNI project(app). For example, I need to do addition(+) operation that logic is written in C++ code. Need to send 2 (a,b) arguments from the Java(android app) it should reach C++ code. My Question is which location do I need to create C++ file in AOSP? how to pass two arguments (a,b)to C++ code ? how to receive the sum (a+b) value from c++ to java(android) app ?. – GNK Jul 18 '22 at 05:38
  • @GNK for something that simple, I would use a memory-mapped file instead. However, as an example, if you use Sockets, you don't need to worry about locations, only port numbers. For memory-mapped files, both programs just need write access to the same file. If you don't need persistence, you can use a tmpfs. – Peter Lawrey Jul 19 '22 at 05:44