Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I choose Boost Asio or Aysnc Socket threads in Android?

I am in process of developing an network based UI app for Android which would perform following kind of functionalities

  1. Needs to communicate with TCP servers running on n/w based embedded devices (>100 at a time).
  2. Polling these devices at regular intervals for fetching updated information
  3. Sending and receiving information from those devices
  4. All above information would be controlled and managed by application's UI

Considering above situations, the app would probably have to spawn multiple thread's for multiple connections and managing them.So my query is

  1. Is it good approach to develop the network module using Boost.Asio libraries ? Or it is okay to open upto 100 of socket threads for connectivity?

  2. If Boost.Asio is used, then network module would be developed seperately using NDK, to access JNI would come into place, which in turn could lead to slow response?

Alternatively, can there be other better options? Looking forward for your inputs!

Many thanks in advance.

like image 809
Rohit Avatar asked Nov 04 '22 08:11

Rohit


1 Answers

I suggest taking a look at New I/O, which is supported on Android. Using it you can handle multiple connections in a single thread, the API is similar in principle to Posix select() call.

If you decide to go for your second option (networking code implemented in C/C++) I don't think you should be worried about JNI performance. Significant part of Android APIs is just a thin JNI wrapper on top of C/C++ anyway.

like image 184
Code Painters Avatar answered Nov 09 '22 17:11

Code Painters