Listening to broadcasts when server and client are on the same machine

后端 未结 1 852
鱼传尺愫
鱼传尺愫 2021-01-14 01:32

After spending better part of the night, I haven\'t been able to make it work. Here is what I\'m doing:

  1. This is a network game that is hosted by one participan
1条回答
  •  礼貌的吻别
    2021-01-14 01:58

    Figured it out with the help of MS guy. This seems to be a bug in DatagramSocket class. You need to send at least one message on the multicast group before you start receiving multicast data from other advertisers. As a workaround, you can send an empty message before you start listening. More details and sample code can be found on this SO post (which is an absolutely simplified version of this question).

    Additionally, it confirmed the following:

    1. You can have more than one sockets using the same host/port if you set Control.MulticastOnly to true on the advertiser socket.
    2. Advertiser socket does not need to call BindServiceNameAsync() if it is only doing multicasting.
    3. 237.1.3.37 and any other address in the multicast range works for multicasting. 255.255.255.255 is not needed and shouldn't be used.

    Hope this helps someone down the road.

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