views:

44

answers:

3

I am using Objective-C and Java for this, but I think the question is language-neutral.

I have an iOS client that talks to a Java server over TCP/IP. Right now I need to tell at least one of the parties the IP address of the other. Is there a standard way that I can "discover" IP addresses (from one side or the other)?

Also, how would switching to UDP affect the answer?

+4  A: 

There are many protocols for discovering other devices/servers on the network. One of the most commonly used in the iOS realm is "Bonjour". Look at Apple's sample apps.

Darron
thanks Darron, I wonder if it'll be possible to get a Java app to serve as a Bonjour-discoverable service?
Yar
wow, there's a whole world to this. http://stackoverflow.com/questions/1233204/are-there-any-other-java-libraries-for-bonjour-zeroconf-apart-from-jmdns fascinating.
Yar
A: 

Is there a standard way that I can "discover" IP addresses (from one side or the other)?

Yes, it's called "port sniffing" and will certainly get you in trouble since it's a common kind of attack.

You simply try all IP addresses in a range. Many firewall products will consider this an "intrusion" attempt and log you with the intrusion detection software.

We almost never "discover" addresses.

That's what "domain names" are for.

S.Lott
Thanks @S. Lott. Perhaps I stated the question too narrowly. The reason I want to do this is that I have an iOS app that I want to connect to a server on a computer that is right next to it. I can't use domain names because I cannot ask a Desktop-computer user to make sure his/her computer responds to a domain name.
Yar
@Yar: "Right next to it" doesn't mean anything on the internet. Connectivity is not trivial. Don't try and make it trivial -- doing so allows a variety of unwanted activity. The desktop computer user must know their machine's IP address or must be able to find it. Otherwise, the entire conversation between machines cannot be trusted. Please read up on "man-in-the-middle attacks". You might be creating a security disaster of you're not very careful.
S.Lott
Thanks, while I'm aware of man-in-the-middle attacks, IP spoofing is one of the techniques used to perform them. Therefore having users key in a server's IP address on an iOS client would hardly "solve" the security issue. But anyway, what I was really looking for was something like http://jmdns.sourceforge.net/ which is one way of doing DNS discovery. Security issues can be handled the same way they are with Bluetooth pairing, to give one example.
Yar
@Yar: having users key in a server's IP address make the user part of the security solution. Indeed it does "solve" the problem. Security is things people actively "do". Where else does trust come from except checking? As with all hand-shaking pairing techniques. Bluetooth, SSL, etc.
S.Lott
@S. Lott, good point, in any case the original question was poorly stated. Thanks for your time as always.
Yar
A: 

Why can't the server have a well known DNS name?

dty
While I'll be able to run some software on the "server," I won't be able to configure its DNS (or any other aspects of it). Both of the machines will be on the same subnet.
Yar
If they are on the same subnet, then a simple UDP broadcast will usually suffice. Have the client send a broadcast to the subnet broadcast address on a specific UDP port that the server is listening on. When the server receives the broadcast, it can reply directly to the broadcasting client with its TCP IP/port.
Remy Lebeau - TeamB
Thanks @Remy... now I'll have to figure out what a "simple UDP broadcast" means. If you know of any links, let me know.
Yar
To get the subnet's broadcast IP, mask the client's IPv4 address with the subnet and then append the inverse of the subnet mask. In other words: `broadcast_addr = (ip_addr `. For instance, if your client has a LAN IP of 192.168.0.1 and a subnet mask of 255.255.255.0, then the subnet's broadcast IP is 192.168.0.255. Once you have that, then you can send a normal UDP data packet to that IP, containing whatever content you want. If your UDP listening server is bound to an IP on the same subnet, then it can receive the UDP packet via a normal read operation.
Remy Lebeau - TeamB