Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inter-process-communication between a Java application and a local server

Firstly Cheers to all PROGRAMMERS [ Today = Programmers day :) ]

Secondly, I'm working on a project where the specifications require using a server as a front end and an application in the back end. The project is an advanced smart home system. The server will handle commands coming from the client through the internet (let's say like a remote control from outside the house) and send them (through a channel of communication) to the application (planning on using JAVA application) which will handle the main logic like controlling hardware stuff (lights ...) , reading from a microphone (local mic) and accessing a database to act as a speech recognition system (offline).

Now I'm still in the planning phase and I'm not sure which technologies are the best for this project. I'm thinking to use Node.js or Apache as the server and a JAVA application as the back end and any SQL database for the application's SRS.

I hope this illustration demonstrates clearly how the system works:

enter image description here

The main question is:

What is the best way to make the Java application communicate with the server (communication channel [must be bidirectional]) ?

and Do you recommend a specific server other than the mentioned ones for this job ?

What crossed my mind so far:

1- JSP and servlets (making the server is the application too). But I don't want a server to handle the offline stuff and I'm not sure if java servlets can access hardware interface. I also want the server to be separate from making critical decisions (different layer for security reasons and since it won't be used as frequently as the local [offline] system).

2- Communication channel :

A- A shared file, but it's a bad idea since I don't want the application to check if the file contents changed (command received) or not from time to time (excessive operations).

B- A an inter-process-communication through a port (socket communication) seems the best solution but I don't know how that would turn in terms of operation cost and communication errors.

OS used : Linux Raspbian

EDIT:

I'm sure ZMQ+Apache is good enough for this task, but how is it in comparison to WebServices (like SOAP) ? Would WebServices be a better solution in terms of standard implementation and security ?

All related suggestions are welcomed, TQ

like image 280
CME64 Avatar asked Sep 13 '13 20:09

CME64


1 Answers

ZeroMQ is great for internal communications, or any other similar communication solutions.

For specifically your case, I can see that ZeroMQ would be a best fit.
Reasons:

  • You offline server have to be agnostic to web solution.
  • Communication can be reliable and bi-directional, possibly another patterns like (pub>sub, req<>res, etc).
  • Restarting any of sides would not require to restart the sockets (connection) on other side, as messages are queued.
  • Possibility to scale not just on same hardware, but as well to local area network or even through internet.
  • Big community of support. It might look a bit hard to get into, but in reality it is dead simple, just go to examples and once concept understood - it is very easy and neat to work with.
  • ZeroMQ has lots drivers for most popular languages, that includes Java and Node.js.

Considerations:

  • You need to think over packets and data will be sent. So some popular data protocols like XML or JSON is good way of thinking.
  • Responsibilities over different services - make sure they are not dependant on each other too much. Or if main offline server - is a core of system, make sure it does not depend on web facing service, so that web face can be removed/replaced/improved etc.

Few more points to think about:
Why Java, and what about modular approach? For example if you want to expand and scale - add more sensors into smart home solutions, then having one giant application would require to change it, it is harder to maintain as well as maintain different clients with own needs. Think modular way - some core functionality for offline stuff, but many aggregator processes that would talk to different sensors. This makes easier to support different setups and environments, as well maintain the system as a whole by improving independent components.

like image 193
moka Avatar answered Oct 06 '22 15:10

moka