views:

90

answers:

1

Hello all,

I am currently learning about basic networking in java. I have been playing around with the server and client relationship between two of my computers. However, I cannot figure out how distributed programs (say, a videogame), can not only find the 'host' computer, but also the port number on which the server is running in order to create a Socket between the two computers. The only way I really see to create a Socket is with an already known IP Address, and with a known port number.

How do you search a LAN network for another computer (host) searching for clients?

How do you determine what port the server is located on without 'pinging' all available ports for a response (which, I understand, is bad form... Something about 'server attack'...)?

In such a situation as a video game, there can be any number of computers on the same network, and any number of them might be attempting to host, or otherwise running the application. Any other important information, or perhaps reference to a more detailed tutorial than the one I am using, regarding making connections on so very little information on the client side would be appreciated.

Many thanks,

Jonathan

+3  A: 

Normally services/schemes have a given port number or range of port numbers that they use (HTTP uses 80, SSH uses 22, etc.). Additionally, they may connect to a "master" server in order to announce their presence and learn about other nodes (e.g., Battle.net).

Neither of these is strictly needed if Zeroconf is used (via Bonjour, Avahi, etc.). Zeroconf allows machines to do multicast DNS on a LAN instead of the pointcast mechanism traditionally used for DNS. This allows them to discover machines across the network that also support mDNS, and to discover services running on them.

Ignacio Vazquez-Abrams
So you are saying that in addition to the connections between the two computers, they must connect to another server who's location is fixed (presumably over the internet) to 'find' each-other?
Jonathan
If an address isn't explicitly given by the user, then yes. It is impractical to scan the entire Internet looking for other machines running compatible software.
Ignacio Vazquez-Abrams
I am working with a local area network, but your point is true regardless. Thank you very much.
Jonathan