Reputation: 196
I build a webserver on my android device by NanoHttpd or ServerSocket and connect to this server from itself. It run good when device is online. But I can't receive request when device isn't online. I was try connect to localhost
or 127.0.0.1
but nothing happen. Is there anyway to establish connection to localhost
when device is offline?
Thanks
Upvotes: 2
Views: 587
Reputation: 9034
Try constructing your server using NanoHTTPD(String host, int port) constructor and specify either 127.0.0.1
(for localhost loopback interface) or 0.0.0.0
(for all interfaces). This way you will be able to connect to your server regardless of device's connectivity.
public class MyHttpd extends NanoHTTPD {
public MyHttpd(){
super('0.0.0.0', 8080);
// ....
}
// ....
}
Upvotes: 1