Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 897
user917959 Avatar asked Oct 19 '25 16:10

user917959


1 Answers

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.
like image 141
Alex Bakulin Avatar answered Oct 22 '25 04:10

Alex Bakulin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!