How to connect iPhone Safari to Windows HTTP server? - iphone

I'm completely new to the iPhone, so this is a newbie question.
The web development environment I use at work is set up on Windows 7, running Tomcat as a web server. Web Apps are tested by pointing a browser to "localhost".
I've been asked to port a web front end to the iPhone. Since I need to use this same development environment I need to connect the iPhone to the PC via USB or Ethernet.
There is this answer:
"http://stackoverflow.com/questions/3132105/how-do-you-access-a-website-running-on-localhost-from-iphone-browser"
but I was hoping to do it without wireless.
Other questions I've researched are about iPhone development, the SDK, etc. I'm not developing iPhone code, only trying to get the iPhone Safari browser to access the IP address of the local PC, 192.168.xx.xx or whatever.
Seems like it should be simple, a matter of cabling?

it would be an issue of cabling... if the iPhone had an eternet jack :)
But the wifi connection is the only "network jack" the phone has that you can connect to your own network directly with, the 3G or CDMA port gets routed via your mobile phone company, nothing you can do about that. Hence the need for WiFi to access non-routable addresses, like ...
Another option would be to make your server internet-routable, like middapark said. Then you can access it via your mobile phone provider's network and the public internet and can do away with the need to use Wifi.
A third option is to create a VPN tunnel from your iPhone to your local network, again via your mobile phone provider's network and the public internet. But I have no expereince with doing that, so I can not give further advice there.

The problem is most likely because you're trying to get your iPhone to view an internal (i.e.: not internet viewable) network. (Address such as 192.168.0.0, 172.16.0.0 and 10.0.0.0 and are non-routable as far as the internet as a whole is concerned.)
As such, unless you can access your internal network via wifi (or you're prepared to expose the machine in question to the internet, in which case you'll need to use a different IP address) this isn't possible.

Related

LAN web server for testing my websites on my phone?

I am a front end web developer.
I would like a web server on my local wifi network for testing my websites on my phone. I am aware that there are several options out there but witch one would be best for quick testing of multiple websites (also a GUI would be preferable)
Thanks
What you want to do is pretty complex. You have to create and configure a DNS server then you have to configure your phone to get this DNS, etc.
If your phone is an android the best solution is to use your USB Cable and put your phone in dev mode, then you can debug your site with chrome directly on your phone.
how to: https://developers.google.com/web/tools/chrome-devtools/remote-debugging/
For iPhone i don't know if is possible. But the common solution is to use the simulator.

iPhone as proxy for data upload

I want to create an iPhone application that can call web services on a computer, and then upload those files over the iPhone 3g connection. Is there an elegant way to do this?
I tried connecting the phone to local Wifi, but connecting to Wifi disables 3g, even though the Wifi is local network only.
I assume the same problem would arise if I could network the phone with the computer via bluetooth.
Any other ideas? The purpose is to go up to a special demo PC we created, pull some data off, then upload to the Internet, all within proximity of the machine. Unfortunately, it appears that I can't use one connection for pulling data, and another for pushing.
Your assumption is correct. When connecting to both 3G and Wifi, the Wifi connection will be used. Sounds like your local network has no route to the Internet. Perhaps that could be fixed.
Apple does not prefer its iPhones to be used as routers.
If you're working on something that will not be distributed through the App Store, you may have some success looking at "tethering" applications and their source code, which can be found by some clever Googling.

if I have an iphone's IP address is there anyway I can communicate with it?

are there any services running by default on an iphone that would let another ip address communicate with it if the iphone's ip is known?
Yes, technically, you can. There are a couple of issues though:
Mobile IP addresses usually change
When the phone is in sleep mode, its network interface is probably not reachable.
So I don't think you can rely on that for initiating a communication with the phone.
There aren't many options out of the box on a non jail-broken phone. However, you can write your own client application that runs on the phone. It accepts or initiates the remote connection.
And in that case, the protocol is entirely up to you.
If you jailbreak your phone, you can install the OpenSSH package and have SSH and SFTP access to your phone.
I don't know exactly what you want to do with your app, but you can consider create a thread detached from the main one (using gcd) and use it to send/receive informations from a server using JSON objects for example. Sure you can use sockets and write a client or something like that.
I suggested a new thread because you can put it running forever (on a enterprise app, I don't know if Apple will approve a thread running on an App for AppStore).
I had to develop an app with a consistent client/server relationship and it was the way I got it working.

iPhone - see app documents folder using wifi?

The iPhone settings have an IP address for the device when it is connected to a wifi network. Is it possible to get this IP address and establish a connection between a desktop computer (on the same network) and the iPhone?
I want to be able to transfer files between the iPhone and the desktop computer. Some apps like the "Files" and "FourTrack" apps do this.
Can someone please guide me to where I can start?
Thanks a lot for any headsup
Google for SIOCGIFCONF and you'll find a bunch of example code in C for getting all your IP addresses. Once you've enumerated your devices, on iPhone they are always in the following order: Loopback, WiFi, WAN.
Once you have that, you can implement a web server with CocoaHttpServer pretty easily. You'll have to hack it to add directory listings and the like, but it's not too hard. It's not trivial, but it's not too bad.
I think you already answered your question... you have to download an app to do this. I use "Air Sharing" and it works fine.

Is it possible to connect a socket between two mobile devices (iPhones) over the internet?

Is it possible to connect a socket between two mobile devices (iPhones) over the internet?
I am trying to discover the IP of each device and connect directly. I know it can be done with Bonjour but that only works on local networks. I need a high speed connection between two devices over the internet.
Thanks.
If you had both the IP's and they were both routable, it should be possible. I'm not sure though if the IP's given out by the 3G network are routable. If you are using WIFI, the IP you get is almost certainly not routable. Assuming you have a routable IP though, it should be possible.
The trick is just discovering the IP of the other device. The best way to do that would probably be to have each device register its IP with a web service when your app starts up, then query that service to find the IPs of other devices.
It might get a bit tricky managing "unregistering" IPs when the app is closed or when an IP changes though, but it should be doable.
ETA:
If you have a server that they can both connect to, you should be able to implement a solution using that server (i.e. without the phones actually directly connecting to each other). This would avoid the issue of having routable IPs for the phones.
As for how to bridge the sockets together - your server program would basicly work like an old-school phone switchboard operator. You'd have some kind of registration & discovery protocol built into the server software that would allow a phone to register itself with the server, query a list of the other phones currently connected to the server, indicate which phone it wants to talk to, and accept connections from other phones.
Once it knows who wants to talk to whom, your server software would connect the two together by reading from one phone's socket and writing that data to the other phone's socket.
Only a suggestion, but if you can get each of them to connect to a third site, you'll then know the address of each. Send the address of phone A to phone B (and/or phone B to phone A) and then have them connect as you see fit.
Have you looked through all the 3.0 features? Specifically peer networking (the existence of which is public).
WiFi routers often have a feature called "Port Triggering" which allows internal hosts (in this case an iPhone) to inform the router that they would like to have a connections on particular port forwarded to them. I have no idea if the iPhone supports this protocol.
For IP lookup you may consider using DynamicDNS if the two hosts are known ahead of time OR as stated above a custom web service if they are not (i.e. friends exchanging hostnames vs. strangers discovering each other)
This is an old thread, but I just came across it. You could use a STUN server (or NAT-PMP) to get the public IP address/port combo and then SMS it over to the other phone. So long as you open a listening port on the first device, then your second device can just connect directly using the publi IP address/port you sent to it in the SMS (SMS push registry can automatically wake up your app on the second device to do this)
I have run into this issue with an app I was developing. I was trying to connect to a PC cell card from an iPhone. The problem is that AT&T doesn't enable mobile termination for iPhones so it is physically impossible for two phones on an AT&T network to connect to one another. This is straight from an AT&T antenna engineer.
I was able to get this to work by having the iPhone VPN into a server and then connect to the PC cell card but other than that, it wouldn't work.
I have a very strong feeling (but no evidence) that the iPhone address is going to be non-routable. Of course it actually depends on the operator but AT&T give out 10.x.x.x addresses.
Apple have sample (desktop) code that uses Bonjour to implement portmapping on a WiFi router that supports UnPnP.