views:

200

answers:

2

Hello,

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

Second -- Firefox, by IP:

FF by IP

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.

+1  A: 

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

John Smith
Yes. In other words, you can't open ports below 1024 except when running as root on a jailbroken phone.
calmh
I presumed this was the case, which it obviously is not, because apps are accessing port 80. Check out Air Sharing. It's a little expensive, but it does it. at least the HD version for iPad.
Kalle
+4  A: 

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
Matt Stevens
I'm not running on the Sim, so that's not the prob -- I guess the socket code is the culprit then. Will poke and comment again!
Kalle
Holy... it worked. You rock, Mr. Matt! :)
Kalle
This of course leaves the problem: what about users who WANT IPv6? I guess you might put in some configuration value somewhere which enables IPv6 if the port is > 1024, but hm, preferably Apple should just let you use port 80, period.
Kalle
The user would need to be on an IPv6-only network for the connection to fail, I don't think you'll find too many in that environment. It would be a good idea to file a radar on this, the behavior should be consistent.
Matt Stevens
It seems, like it isn't working anymore with 4.0.2
vikingosegundo