2

I made a webserver on my android device(using Nanohttpd). It's working fine over the port 8080 but I want to make it okay over the port 80,(I want to tape on my browser : http://192.168.x.x instead of http://192.168.x.x:8080/ ) but I'm not able to do it

This is how I call the method that creates the webserver:

httpServer = new NanoHTTPD(80,Environment.getExternalStorageDirectory());
  • Can someone tell me what service is running by default over the port 80 ?
  • How can i fix this problem ?
Stephan
  • 41,764
  • 65
  • 238
  • 329
AndroidM
  • 411
  • 4
  • 7
  • 20
  • Can you post where you got the library from because the constructor you are using does not seem to be a standard NanoHTTPD constructor. They originally only have `NanoHTTPD(String hostname, int port)` and `NanoHTTPD(int port)` – JRomero May 28 '13 at 17:22

3 Answers3

3

I finally found a way to fix that, for those who have the same problem, here is the solution

  • I rooted the phone using UnlockRoot

  • then I installed Port redirector from the play store and I forwarded the traffic from port 80 to port 8080, and now my web server is available from the address: 192.168.x.x

Hope it will help :)

its_notjack
  • 323
  • 3
  • 17
AndroidM
  • 411
  • 4
  • 7
  • 20
  • An alternative port redirector on the play store: https://play.google.com/store/apps/details?id=at.bherbst.net&hl=en – its_notjack Oct 27 '15 at 17:37
1

Ports below 1024 are restricted on Unix like systems. You need superuser privileges to bind to these "well-known" ports.

List of these "well-known" ports on wikipedia

Rajesh
  • 15,724
  • 7
  • 46
  • 95
  • if i 'm root, how can i do it – AndroidM May 28 '13 at 18:45
  • Check this question: http://stackoverflow.com/q/7295873/1321873. After assuming the superuser privileges, you can directly run the webserver on port 80 without the need for port forwarding. – Rajesh May 29 '13 at 05:02
  • @Rajest - actually, no, that won't directly work (the post you link is rather misleading). One would have to use `su` to start the webserver in its own root process, or perhaps have a shim which opens the listening socket and then passes the scoket through a unix domain socket to a non-root web server to use (not sure if that would work) – Chris Stratton Jun 01 '13 at 02:11
0

Check out line 89 of the server source:

https://github.com/NanoHttpd/nanohttpd/blob/master/core/src/main/java/fi/iki/elonen/NanoHTTPD.java

I don't even see a constructor that type-matches your arguments. That might be part of the problem.

JLindsey
  • 700
  • 2
  • 7
  • 14