DatagramSocket throws Exception while sending to multicast group

0

I try to send some data to a multicast group. This worked for sometime, but now I get an exception. The Exception says that the hostname can't be resolved (HRESULT: 0x80072AF9).

The hostname he tries to resolve is the ip address (224.5.6.7). This exception doesn't occurs on my Surface RT but on the Surface Pro.

With this sample I could produce the error:

    private async void Test()
    {

        try
        {
            var socket = new Windows.Networking.Sockets.DatagramSocket();
            var localAdress = CurrentIPAddress();
            var port = "40404";
            const string M_GROUP = "224.5.6.7";

            socket.MessageReceived += (sender, ev) => {
                System.Diagnostics.Debugger.Break();

            };

            await socket.BindEndpointAsync(new HostName(localAdress), port);
            socket.JoinMulticastGroup(new HostName(M_GROUP));


            //HRESULT: 0x80072AF9
            var stream = await socket.GetOutputStreamAsync(
                                         new HostName(M_GROUP),
                                         port);
            await stream.WriteAsync(new byte[] { 3 }.AsBuffer());

        }
        catch (Exception e)
        {
            System.Diagnostics.Debugger.Break();
            throw;
        }
    }

    private string CurrentIPAddress()
    {
        var icp = NetworkInformation.GetInternetConnectionProfile();

        if (icp != null && icp.NetworkAdapter != null)
        {
            var hostname =
                NetworkInformation.GetHostNames()
                    .SingleOrDefault(
                        hn =>
                        hn.IPInformation != null && hn.IPInformation.NetworkAdapter != null
                        && hn.IPInformation.NetworkAdapter.NetworkAdapterId
                        == icp.NetworkAdapter.NetworkAdapterId);

            if (hostname != null)
            {
                // the ip address
                return hostname.CanonicalName;
            }
        }

        return string.Empty;
    }

The Exception happens when GetOutputStreamAsync is called.

In both Systems the Sockets are bound to an ipv4 address.
Both Systems are up do date. (29. May 2014)

c#
windows-runtime
multicast
datagram
asked on Stack Overflow May 29, 2014 by lokimidgard

1 Answer

0

User contributions licensed under CC BY-SA 3.0