user917959
user917959

Reputation: 81

Network Discovery of Servers

Ok, so I understand that communication between a client computer and a server computer can be initiated in windows with the creation of a socket between the two computers, but every tutorial that I have seen depends on the End User knowing the IP address of the computer that they wish to connect to.

In local network LAN games, however, the clients somehow autodetect the server. How is this done? Does the client autocheck every possible IP, is there some sort of "GetDetectedIPs" api, etc?

Im looking for answers that can be implemented in standard WIN32 API in straight C. No MFC, .NET, or C++ please. Thank you.

Upvotes: 4

Views: 2560

Answers (3)

Alex Bakulin
Alex Bakulin

Reputation: 1668

The technique you need is called broadcasting. It's used, for example, in BOOTP and DHCP protocols.

Sending a packet with broadcast destination address results in it being received by all devices in LAN. Broadcast address is an IP address in which the host identification field is filled with ones:

bcast_addr = ~netmask | my_addr;

The discovery process is usually like follows:

  1. The client sends a UDP datagram with broadcast destination address at specific port.
  2. The server listens on this port and receives the datagram. Other computers discard it.
  3. Server sends all the necessary info about itself to the client by a usual UDP datagram.

Upvotes: 4

Nikolai Fetissov
Nikolai Fetissov

Reputation: 84151

This is usually done with zero-conf. Microsoft version of it is Simple Service Discovery Protocol.

Upvotes: 3

fourcube
fourcube

Reputation: 9

You could just let the client send an UDP packet to every IP in a specified range and let the server answer with another UDP packet.

Upvotes: 0

Related Questions