Domanda

I'm on writing an Android App thats purposed to hand commands (or better data) to a running c daemon on another machine in the same network (should also work from an external network sometimes in the future), but I have problems to choose the best way (or protocol) to do that.

Communicating with an sort of API (PHP, Python, etc.) isn't really a option (maybe I'm wrong with this) because that data is time critical, should be the fastest way thats possible, so I trying to avoid the overhead coming with http and another thing between the daemon and the APP. On the other hand the daemon should be accessible by an local running PHP script too (there should be an API in the future, so maybe the extra "layer" isn't that critical?). But even if I choose the API solution, what's the best way then? Sockets, general IPC?

Any suggestions or experience with a similar situation would be helpful.

È stato utile?

Soluzione

In your question you say that it's time critical but also that it's under the same network. As far as your application doesn't have any performance problems, you won't find any issue with times. It depends also on your daemon though.

I've worked with a lot of even remote daemons and TCP sockets have always been a good option, I've never had any limitations using them, just be sure to choose between implementing a Service if your socket will need to be alive all your app's life cycle, or an AsyncThread or Thread if it's for a limited task.

This is what I use, for instance:

socket = new Socket();
socket.connect(new InetSocketAddress(host, port), timeout);

in = new BufferedReader(new InputStreamReader(socket.getInputStream(), "ISO-8859-1"));
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top