Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android service to listen to a specific port

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

like image 398
mehdouch Avatar asked Jun 13 '11 15:06

mehdouch


People also ask

What is port listening?

The Listening Ports section of the Network tab gives you information about the services and processes on your system that are waiting to service network requests. These services are listening on either a TCP or a User Datagram Protocol (udp) port.

How do I allow a port to listen?

Navigate to Control Panel, System and Security and Windows Firewall. Select Advanced settings and highlight Inbound Rules in the left pane. Right click Inbound Rules and select New Rule. Add the port you need to open and click Next.

Do Android phones have open ports?

University of Michigan researchers discovered that a number of Android apps in the Google Play Store essentially turn smartphones into servers and, as a result, expose the smartphones with insecure, open ports.


1 Answers

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.

like image 64
Steve Prentice Avatar answered Oct 22 '22 01:10

Steve Prentice