I need each computer running my program to send out their IP over and over to the multicast, and I need each computer running to be able to build a list of available hosts running the program. Is there any way to do this with UDP in C#?
Asked
Active
Viewed 246 times
0
-
If you are planned to use TCP then put a timer in your TCP Client programm and try to connect to the TCP server if not connected. and in your TCP server side take the remote IP address form sockets RemoteEndPoint. – Rezoan Sep 29 '13 at 13:51
-
@Rezoan That wasn't what I meant. I don't want to have to connect to a server to have to get its IP. I need to get a list of available servers. UDP is connectionless, and I need the server to broadcast its IP so the program builds up a list of available servers. – user2454031 Sep 29 '13 at 13:56
-
ohh got it. i just say you can accomplish in this way. – Rezoan Sep 29 '13 at 14:01
-
See this: http://stackoverflow.com/questions/10832770/sending-udp-broadcast-receiving-multiple-messages may be this article put some light on your requirement – Rezoan Sep 29 '13 at 14:06
-
1I think it would be more reliable to have a single server keep track of this list. Each server could make a reliable TCP connection to it every X seconds/minutes which would let the server know it's still available and could also retrieve the list of available servers if it needed to. – itsme86 Sep 29 '13 at 14:21
-
How would it know what the server's IP is? – user2454031 Sep 29 '13 at 16:09
1 Answers
0
What you want is broadcast NOT multicast. Yes this is possible, you need to:
- Send data to a broadcast address, e.g. 192.168.255.255 on the port no. your hosts are running on. This will send the data to everyone connected to the 192.168.x.x subnet. (255.255.255.255 is valid - to send to everyone - but that is almost always dropped and probably will not work).
- You do not need to include your IP in the broadcast because the recipient can see the IP end point they received the data from.
NOTE: Firewall's, NAT and the like will usually drop incoming unsolicited data unless specifically told to allow/forward it. On LANs what is described above usually works without changes.

markmnl
- 11,116
- 8
- 73
- 109