I’m writing a java application which runs on the local machine, it needs to interact with another program (also running on the local machine), the other program has a JSON RPC API which is the best way to interact with it. However, in googling around I found a lot of libraries for exposing JSON RPC methods from a java application but nothing good on how to call a remote JSON method. How would I do this?
The two things I’m looking for are:
- A way to create new JSON objects
to send - A way to connect to the
other program and send my response - A way to decode the JSON response
For interacting with JSON text in Java, see JSON in Java. Use this for building JSON request objects and serializing them to text as well as de-serializaing the response from the RPC server.
Is this over HTTP or a plain TCP connection? If the former, use
HTTPClient. If the latter, just open a socket and use its I/O streams.