Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 540
Jamey McElveen Avatar asked May 01 '09 13:05

Jamey McElveen


3 Answers

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.

like image 97
Eric Petroelje Avatar answered Sep 24 '22 22:09

Eric Petroelje


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.

like image 45
KevinDTimm Avatar answered Sep 22 '22 22:09

KevinDTimm


Have you looked through all the 3.0 features? Specifically peer networking (the existence of which is public).

like image 23
Kendall Helmstetter Gelner Avatar answered Sep 24 '22 22:09

Kendall Helmstetter Gelner