I am building an Android application which has a server that listens to multiple incoming connections, and also have multiple outgoing connections.
I have 1 main activity and 2 helper classes: Server and Client. They both extend ASyncTask for multithreading.
I am planning to use Selector for this job. And so, I am planning to use SocketServerChannel for the server class, while having multiple SocketChannels for my client class. These Channels will be handled by the Selector.
My question is, since I am using 1 single server and ASyncTask, is it redundant to use SocketServerChannel and Selector for my Server class? Or should I still use it to manage the multiple incoming connections?
EDIT: I found another way to do this. It is very inefficient, but it gets the work done. I just use normal Sockets and ServerSockets, and for all possible outgoing connections, I create a new Socket that is one-time use only. This way, I don’t have to bother with keeping track of all of my connections.
Java.nio is often more complicated than using java.io and necessarily more optimal in terms of speed and load.