In my program, I am receiving data via socket in an IntentService class and then sending the same as a broadcast to activity. Activity processes the input and prepares an output.
while (true) {
socket = serverSocket.accept();
//Read data from socket
//Publishing as a broadcast }
Now my question is
- How can I send the output from activity to the intentService?
I know that I can fire a fresh intent to the intentService but since my while loop is already running in an infinite loop, won't this be queued and possibly never executed?
- Even if I manage to get data from activity to the intentService, how can I use the same socket connection to write back to the client or should I create a separate thread for the same?
Any insight would be helpful.
Copyright Notice:Content Author:「Raghav」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30767302/socket-listener-in-intentservice