C
chrisrocker90
I have to link together a couple of programs in which a Java process
passes a TCP stream to a C++ process, which then transmits the data to
a remote host.
As I see it, I have two options.
The first is to pass the TCP stream to the C++ process by using a JNI
call. I'm not quite sure how it would work - it would just be a wrapper
to a method I would install in the C++ process I guess. But it seems
like a "tightly coupled" solution, although that might not be too bad
if it's only one method call. Also, I'm not sure how much buffering
goes on when you make a JNI call. Also, JNI code seems kind of messy
and complicated to maintain, partially because of the wierd C syntax
and the various JNI objects. The real problem I have with it is that
it's an additional layer to maintain.
The other solution sounds better initially, which is using a local TCP
connection to pass the stream to the C++ process, which would then
rewrite the stream to its own socket. I would need to figure out how to
handle sockets in C++, which from what I've seen is no picnic either.
But it would save me the headache of a third JNI layer.
However another important if not overriding consideration is speed.
Would passing it through the JNI layer be faster or slower than passing
it through the local IP stack? They both need to copy and read from a
buffer at least once, I would think.
Any thoughts or insights are welcome.
- chris
passes a TCP stream to a C++ process, which then transmits the data to
a remote host.
As I see it, I have two options.
The first is to pass the TCP stream to the C++ process by using a JNI
call. I'm not quite sure how it would work - it would just be a wrapper
to a method I would install in the C++ process I guess. But it seems
like a "tightly coupled" solution, although that might not be too bad
if it's only one method call. Also, I'm not sure how much buffering
goes on when you make a JNI call. Also, JNI code seems kind of messy
and complicated to maintain, partially because of the wierd C syntax
and the various JNI objects. The real problem I have with it is that
it's an additional layer to maintain.
The other solution sounds better initially, which is using a local TCP
connection to pass the stream to the C++ process, which would then
rewrite the stream to its own socket. I would need to figure out how to
handle sockets in C++, which from what I've seen is no picnic either.
But it would save me the headache of a third JNI layer.
However another important if not overriding consideration is speed.
Would passing it through the JNI layer be faster or slower than passing
it through the local IP stack? They both need to copy and read from a
buffer at least once, I would think.
Any thoughts or insights are welcome.
- chris