Hello fellow programmers! I am writing a program in C++ that is supposed to allow for real time data transfer between 2 computers over LAN using windows sockets. Since the data is supposed to be transferred as fast as possible I use UDP (this is a game, therefore only the newest data is relevant). Now, since I tested it on single machine i use the following code to assign server IP to the client
Now, I need it to run within LAN where the exact addresses of server and client will be unknown. How to connect in such a case? Is it enough if I broadcast to 255.255.255.255?
Yeah, I understand that it is not really safe to broadcast to all the net. However, this is part of an assignment I got, where I am told to not to hardwire IP addresses. Is there a simple way to avoid it?
I guess the most normal way to do it by using multicast DNS.
When an mDNS client needs to resolve a hostname, it sends an IP multicast query message that asks the host having that name to identify itself. That target machine then multicasts a message that includes its IP address.
I never worked with mDNS, but if I had to I would surely use it as that quote does what you need, assuming your client will need to know server computer name on local network.
there may be other ways, I don't know but client not knowing to where to connect just doesn't sound very good.
However, this is part of an assignment I got, where I am told to not to hardwire IP addresses.
What that means is that you're supposed to accept the IP from the user, either directly or from a configuration file, not that you have to broadcast to the entire network.