Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web server on port 80 on iPhone

I've been working on a project for awhile and it's got a built-in HTTP server which runs on port 8080. The users are told to access the device via e.g. http://192.168.1.4:8080/ -- works great. Recently I realized that applications CAN use port 80 to remove the need for ":8080", though if I try to set the port to 80 I get a crash with "General CFSocket error".

Any ideas how to enable port 80 for a web server on an app?

A few screenshots where this is happening:

First -- on the iPad, the app is showing the URLs where you can access it.

iPad
(source: enrogue.com)

Second -- Firefox, by IP:

FF by IP
(source: enrogue.com)

The above are from a real app on the store, it's not jailbroken magic or anything. I know that ports < 1024 are reserved for the admin on UNIX systems, so the above app is obviously doing something specific to get access to the port.

like image 421
Kalle Avatar asked Jul 24 '10 16:07

Kalle


2 Answers

You can bind to port 80 on the device's IPv4 interface but not the IPv6 interface and not in the simulator. You'll need to modify your socket code to only listen on the IPv4 interface, for the simulator you can conditionally use a different port:

#if TARGET_IPHONE_SIMULATOR
    [httpServer setPort:8080];
#else
    [httpServer setPort:80];
#endif
like image 119
Matt Stevens Avatar answered Sep 26 '22 21:09

Matt Stevens


iPhone is unix based. Ports below 1024 are reserved for the root/superuser. You need to be root in order to use those ports.

like image 28
John Smith Avatar answered Sep 23 '22 21:09

John Smith