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.
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"));
建议使用socket 进行,但是很可能会遇到一些selinux权限问题需要修改,如果守护进程本身支持binder的话,其实也是可以使用binder进行跨进程通信的
最后如果是没有做过framework建议这个视频
FrameWork入门课视频链接:https://edu.csdn.net/course/detail/30298
FrameWork实战课1视频链接:https://edu.csdn.net/course/detail/30275
Android Framework学习难度相对应用难度较大,所以桌面才学习更加简单呢?
发现一个不错的博客:https://blog.csdn.net/liaosongmao1/article/details/117135491