'Socket programming: How a socket client may discover server IP address inside LAN?

Scope:

  • OS: MACOS, Windows;
  • Language: C++Boost library;

Description:

LAN has N computers with MacOS and Windows operating systems, where N ≈ 10. The IP addresses of the computer are not static and assigned by the network. On one of these computers (machine S) a socket server application is running. And on another machine (machine C) a client socket application is running. This is not a static setup, and next time it might be different computers with different IP addresses.

Update:

a server machine -- is a slave. A client machine is a master. A user can install client software in any computer in LAN, and server software in any other computer in LAN. Server take responsibility for the calculations which takes a lot of resources and just send a result to a client. So, the main idea is: a user of a master computer should not provide a server IP address, but the client soft should be able to discover it by itself.

Task: Client socket application does not know Server application IP address, and should be able to discover it. Solution should be a cross-platform one (Boost C++)

Please suggest the best practices.

My best guess was: retrieve all the IP addresses of connected devices and socket->send_async_to them. And if I get answer in handle_receive callback -- this is a server app. But I did not find a way how to get all the IP addresses of LAN devices.

Thank you in advance for your suggestions and ideas.



Solution 1:[1]

use UDP to send request to all the computers in the network.Write a thread in server to respond udp request. then you can get response from the server and get the socket ip.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kamal Paulsamy