I'm building an android app with xamarin. In it I need to load files from a local storage through a webserver into a webview. So I used NanoHttpd to create a webserver to serve files to the webview. Iloaded the jars into a jar binding library. Started a web server the same way as in the samples. Unfortunately when I try to load http://localhost:8080/ in the webview I keep getting err_connection_refused. I'm loading the app in a Sony Xperia device.
I tried alternatives to NanoHttpd too. EmbedIO for exaple. I tried to used the included SimpleWebServer or make my own that will return even a simple string just to see that it's working. I tried to load 127.0.0.1 or localhost, tried different ports. Nothing works.
Help me StackOverflow, you're my only hope.
Edit to add some code
This is an example implementation copied from the helloserver sample
class HttpServer : NanoHTTPD
{
public static void main(String[] args)
{
ServerRunner.Run(Class.FromType(typeof(HttpsServer)));
}
public HttpServer():base(8080)
{
}
public HttpServer(int port) : base(port)
{
}
public NanoHTTPD.Response serve(NanoHTTPD.IHTTPSession session)
{
NanoHTTPD.Method method = session.Method;
String uri = session.Uri;
//HelloServer.LOG.info(method + " '" + uri + "' ");
String msg = "<html><body><h1>Hello server</h1>\n";
var parms = session.Parms;
if (parms["username"] == null)
{
msg += "<form action='?' method='get'>\n" + " <p>Your name: <input type='text' name='username'></p>\n" + "</form>\n";
}
else
{
msg += "<p>Hello, " + parms["username"] + "!</p>";
}
msg += "</body></html>\n";
return new NanoHTTPD.Response(msg);
}
}
Here's the initialization:
private void StartServer()
{
String[] args = {
"--dir",
Application.Context.FilesDir + "/Website"
};
SimpleWebServer.Main(args);
//HttpsServer.main(null);
// server=new HttpsServer();
// server.Start();
}
Here it's the simplewebserver from the nanohttpd package, result connection refused and logcat shows
[INFO:CONSOLE(12)] "Not allowed to load local resource: file:///android_asset/webkit/android-weberror.png", source: data:text/html,chromewebdata (12)
If I try to start with Httpserver.main I get the same and additionally
java.lang.InstantiationException: class md535a550fd04ddaa12bd0435e04d30336e.HttpServer has no zero argument constructor
If I try to start with new httpserver and then server.start I get just the string "Not Found" on the webview and no logcat errors that I can see