I have a java application I need to pass some info to a C++ program. It has been suggested that I use some simple socket programming to do this. Is this the best way? If not what are the alternatives? If so, how should I go about learning about socket programming?
Naturally, it would be easiest if the second course were also offered in Java, but learning to move from one language to another is a fact of life for today's software professionals. Fortunately, C++ has many features in common with Java, and it is easy for a Java programmer to gain a working knowledge of C++.
Java native interface (JNI) is a framework provided by java that enables java programs to call native code and vice-versa. Using JNI a java program has the capability to call the native C code.
You have a few options:
For learning sockets, a Google search for "java socket tutorial" or "c++ socket tutorial" will give you lots of information.
A simple way to do this is using standard input and output:
class MyTest {
public static void main(String... args) {
System.out.println("carpet");
}
} // Java
#include <iostream>
#include <string>
int main() {
string input;
std::getline(std::cin, input);
std::cout << "from java: " << input << std::endl; // output: carpet
} // C++
# start by piping java's output to c++'s input
$ java MyTest | ./my_receive
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With