Reputation: 81
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
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:
Upvotes: 4
Reputation: 84151
This is usually done with zero-conf. Microsoft version of it is Simple Service Discovery Protocol.
Upvotes: 3
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