How to do a UDP multicast across the local network in c#?

后端 未结 3 1606
庸人自扰
庸人自扰 2020-12-28 21:31

I am trying to get some simple UDP communication working on my local network.

All i want to do is do a multicast to all machines on the network

Here is my se

相关标签:
3条回答
  • 2020-12-28 21:39

    Does your local network hardware support IGMP?

    It's possible that your switch is multicast aware, but if IGMP is disabled it won't notice if any attached hardware subscribes to a particular multicast group so it wouldn't forward those packets.

    To test this, temporarily connect two machines directly together with a cross-over cable. That should (AFAICR) always work.

    Also, it should be the server half of the code that has the TTL argument supplied to JoinMulticastGroup(), not the client half.

    0 讨论(0)
  • 2020-12-28 21:46

    I've just spent 4 hours on something similar (I think), the solution for me was:

    client.Client.Bind(new IPEndPoint(IPAddress.Any, SSDP_PORT));
    client.JoinMulticastGroup(SSDP_IP,IP.ExternalIPAddresses.First());
    client.MulticastLoopback = true;
    

    Using a specific (first external) IP address on the multicast group.

    0 讨论(0)
  • 2020-12-28 21:56

    I can't see a TTL specified anywhere in the code. Remember that TTL was originally meant to be in unit seconds, but is has become unit hops. This means that by using a clever TTL you could eliminate passing through the router. The default TTL on my machine is 32 - I think that should be more than adequate; but yours may actually be different (UdpClient.Ttl) if your system has been through any form of a security lockdown.

    I can't recommend the TTL you need - as I personally need to do a lot of experimentation.

    If that doesn't work, you could have a look at these articles:

    • OSIX Article
    • CodeProject Article

    All-in-all it looks like there has been success with using Sockets and not UdpClients.

    Your chosen multicast group could also be local-only. Try another one.

    Your physical network layer could also be causing issues. I would venture to question switches and direct (x-over) connections. Hubs and all more intelligent should handle them fine. I don't have any literature to back that, however.

    0 讨论(0)
提交回复
热议问题