There are several computers in the local network, some of them are servers. When you start a new server, it performs a broadcast to check how many servers are on the network with a call sign like it, and displays the number of these servers on the console.

The call sign is the usual term.

How to implement it without threads and the most simple?

recvfrom suspends the program while waiting for a response, but I don’t know how many servers are on the network and how many I have to execute these recvs.

  • How I would do it. At startup, the server sends a "who is in charge" message. If no one replies for a while, it becomes the main one yourself and sends a message about it. If there is a “master”, then he, having received a message, updates his lists and sends back to the interrogator information on the state of the network. It remains to solve the problem with the competition of "main", but there is a method of "bully" - who has less ip (if compared as a number or a string), that and sneakers. - KoVadim
  • in posix there is a select function that allows you to wait for data on several sockets and at the same time it can be timed out. There is probably something like that in winapi - Mike

0