I developing an app that connects devices on the same network.
Any devices can be the server, I want clients to be able to find the server automatically without users having to enter the IP address of the server manually.
This is how I plan to do it:
One option here: instead of "iterating" the address range and sending individual packets to each address; you could consider sending a broadcast to the whole subnet.
In other words: your client just shouts "I am here"; the server "hears" that and responds; similar to how protocols like DHCP work.
Edit on the comment on how to react to "broadcast not answered":
Actually, you are now coming closer to those topics that make "distributed" computing hard. There are many problems that could kick in; and many different solutions to them.
It starts with: do you go with one broadcast; or instead try multiple times?! And maybe increase the delays between subsequent broadcasts?
Thing is: nobody here can tell you that. The answers very much depend on your "domain", and what makes the most sense to the users of your application.
My suggestion here: look into existing open source products that do similar things; and study what kind of problems they identified; and how they deal with that. I know, this is pretty broad; but that "broadness" comes out of "the overall subject is really broad".