2

I need for my Node application to be able to send and recieve data to/from an already running Java app or to launch Java app from Node.

So, is there a way to send data from NodeJS to Java and back?

My goal is to have something like this:

// In Java:
J2JSInterface.setReciever(msg -> System.out.println("Message from JS: " + msg));
J2JSInterface.send("Hello from Java!");

// In Java console:
// Message from JS: Hello from JS!
// In Node:
JS2JInterface.setReciever(msg => console.log(`Message from Java: ${msg}`))
JS2JInterface.send("Hello from JS!")

// In Node console:
// Message from Java: Hello from Java!

P.S.: I Tried using JNI and Node Api in one C++ library together, (code) but it won't work because Node and Java will load two independent instances of the library and these instances can't interact with each other. (or can they?)

3
  • 2
    Why don't you use websocket? Commented May 6, 2022 at 15:15
  • @AhmetUğur, I think it would be too slow for my needs, but I should definitely try it... Commented May 6, 2022 at 16:10
  • If you can analyze the data well, websocket should be fine. take it easy Commented May 6, 2022 at 16:19

1 Answer 1

1

I really tend to overcomplicate things...

TCP is the solution for really fast communicating. When I checked the latency, I was shocked, because it was around 0 to 1 ms. Thanks to AhmetUğur for pointing out that I could just use websockets!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.