android service to listen to a specific port

mehdouch picture mehdouch · Jun 13, 2011 · Viewed 9.8k times · Source

I want to know how to set an android service that listen to a specific port e.g. http://127.0.0.1:12345

Answer

Steve Prentice picture Steve Prentice · Jun 13, 2011

Implement your service and use the ServerSocket class to listen for incoming connections and to act on them. Don't call ServerSocket.accept() on your UI thread, though. That'll cause your application to not respond. Instead, create a new thread or depending on your actual scenario, an AsyncTask might be sufficient.