Android端NanoHttpd HTTP服务器同网设备无法访问,如何开启入站连接?
Hey there! Let's troubleshoot why your NanoHttpd server is only accessible on the host phone but not other devices on the same WiFi network. Here are the key fixes to enable inbound connections:
By default, some NanoHttpd setups might bind only to the localhost (127.0.0.1) interface, which restricts access to the device itself. To allow connections from any device on the network, you need to bind the server to 0.0.0.0 (this means "listen on all available network interfaces").
Modify your server initialization code like this:
// Instead of just specifying the port // NanoHttpd server = new NanoHttpd(8080); // Bind to 0.0.0.0 to accept connections from outside the host device NanoHttpd server = new NanoHttpd("0.0.0.0", 8080);
Your app needs the right permissions to accept incoming network connections. Add these lines to your AndroidManifest.xml file:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Additionally, check your phone's app permission settings:
- Go to Settings > Apps > [Your App Name] > Permissions
- Make sure "Network" or "Internet" access is allowed (some devices split this into WiFi and mobile data; enable both just to be safe)
Most Android devices include a built-in firewall or traffic manager that might block incoming connections on port 8080. Here's how to check:
- Open your phone's Security or Privacy settings
- Look for options like "Firewall", "Data Usage", or "Network Protection"
- Find your app in the list and ensure it's allowed to receive incoming connections, or add port 8080 to the firewall's allowed ports list
Some WiFi routers enable AP Isolation (also called "Client Isolation") by default, which prevents devices on the same WiFi network from communicating with each other. To fix this:
- Log into your router's admin panel (usually via a browser at
192.168.1.1or192.168.0.1; check your router's manual for details) - Look for the "AP Isolation" or "Client Isolation" setting and disable it
Double-check that the IP address you're using to access the server is the host phone's WiFi local IP (not its mobile data IP). To find this:
- On the host phone, go to Settings > WiFi > [Connected Network] > IP Address
- Use this exact IP (like
10.54.92.228) when accessing from other devices
You can also test port accessibility from another device using a tool like telnet:
telnet 10.54.92.228 8080
If you get a connection prompt, the port is open; if not, revisit the previous steps.
内容的提问来源于stack exchange,提问作者Umang Mathur

