Example #1
0
        internal static MulticastClient CreateMulticastClient(NetworkInterfaceInfo adapter)
        {
            var client = new UdpClient
            {
                ExclusiveAddressUse = false,
                MulticastLoopback   = false
            };
            var socket = client.Client;

            socket.SetSocketOption(SocketOptionLevel.IP,
                                   SocketOptionName.MulticastInterface,
                                   IPAddress.HostToNetworkOrder(adapter.Index));

            socket.SetSocketOption(SocketOptionLevel.Socket,
                                   SocketOptionName.ReuseAddress,
                                   true);
            socket.SetSocketOption(SocketOptionLevel.Socket,
                                   SocketOptionName.ReceiveTimeout,
                                   5000);
            socket.MulticastLoopback = false;

            socket.Bind(new IPEndPoint(IPAddress.Any, BroadcastPort));

            var multiCastOption = new MulticastOption(BroadcastAddress, adapter.Index);

            socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, multiCastOption);
            return(new MulticastClient(client, adapter));
        }
Example #2
0
 internal MulticastClient(UdpClient udp, NetworkInterfaceInfo adapter)
 {
     Udp     = udp;
     Adapter = adapter;
 }