1

I have two processes: a server process, written in Python, and a client written in Java. These two programs will communicate via sockets, and I am about to begin writing the code to handle this.

I am currently intending to send messages between the two in a JSON format that will provide data and/or instructions for the other process to handle - for example, there would be a sort of "type" variable that would define the nature of the message, such as "error", "get", "set", etc.

However, I am wondering if there is a simpler and/or more direct way of formatting this communication, or if anyone has advice about doing this sort of thing, that would be greatly appreciated.

Thanks for your suggestions.

Nat Karmios
  • 325
  • 1
  • 4
  • 17
  • The best way to this would to use a REST-Webservice to do this. There are numerous frameworks for creating and comsuming such services. JAX-RS for java is the standard and for python see http://stackoverflow.com/questions/713847/recommendations-of-python-rest-web-services-framework . – gregor Jun 20 '16 at 11:07
  • Without more context, this question will get mainly opinion only answers (which is a close reason on SO). Short story: it depends on the actual use case. There are many text line oriented protocols around, as well as binary protocols, and you could use streams or datagrams. JSON is just one possibility among plenty of them... – Serge Ballesta Jun 20 '16 at 12:17

1 Answers1

0

You can consider using protobuf instead of JSON or even gRPC, complete RPC protocol implemented on top of protobuf. The only thing you have to do using protobuf is define messages and services, all the implementation code will be generated.

Using of complete RPC protocol will help you to avoid writing a lot of boilerplate code.

SerCe
  • 5,826
  • 2
  • 32
  • 53