internal static void Join()
        {
            // Initialize the receive buffer
            _receiveBuffer = new byte[MAX_MESSAGE_SIZE];

            // Create the UdpAnySourceMulticastClient instance using the defined
            // GROUP_ADDRESS and GROUP_PORT constants. UdpAnySourceMulticastClient is a
            // client receiver for multicast traffic from any source, also known as Any Source Multicast (ASM)
            _client = new UdpAnySourceMulticastClient(IPAddress.Parse(GROUP_ADDRESS), GROUP_PORT);

            // Make a request to join the group.
            _client.BeginJoinGroup(
                result =>
                {
                    // Complete the join
                    _client.EndJoinGroup(result);

                    // The MulticastLoopback property controls whether you receive multicast
                    // packets that you send to the multicast group. Default value is true,
                    // meaning that you also receive the packets you send to the multicast group.
                    // To stop receiving these packets, you can set the property following to false
                    _client.MulticastLoopback = true;

                    // Set a flag indicating that we have now joined the multicast group
                    _joined = true;

                    Receive();
                }, null);
        }
        public Communication()
        {
            this.buffer = new byte[16];

            this.udpClient = new UdpAnySourceMulticastClient(
                IPAddress.Parse("224.0.0.0"), 1025);

            this.udpClient.BeginJoinGroup(OnJoinCompleted, null);
        }
Beispiel #3
0
 public void Find(Action<IPAddress> callback)
 {
     FoundCallback = callback;
     MulticastSocket = new UdpAnySourceMulticastClient(IPAddress.Parse("239.255.255.250"), PortNumber);
     MulticastSocket.BeginJoinGroup((result) =>
     {
         try
         {
             MulticastSocket.EndJoinGroup(result);
             GroupJoined(result);
         }
         catch (Exception ex)
         {
             Debug.WriteLine("EndjoinGroup exception {0}", ex.Message);
             // This can happen eg when wifi is off
             FoundCallback(null);
         }
     }, null);
 }
Beispiel #4
0
        public IPAddress Find()
        {
            WaitEvent.Reset();
            MulticastSocket = new UdpAnySourceMulticastClient(IPAddress.Parse("239.255.255.250"), PortNumber);
            MulticastSocket.BeginJoinGroup((result) =>
            {
                try
                {
                    MulticastSocket.EndJoinGroup(result);
                    GroupJoined(result);
                }
                catch (Exception ex)
                {
                    WaitEvent.Set();
                    Debug.WriteLine("EndjoinGroup exception {0}", ex.Message);
                }
            },
                null);

            WaitEvent.WaitOne();

            return FoundIPAddress;
        }
        public void Open(Action<bool> callback)
        {
            try
            {
                IsOpen = false;
                channel = new UdpAnySourceMulticastClient(IPAddress.Parse(Address), Port);

                _openResult = channel.BeginJoinGroup((result) =>
                {
                    channel.EndJoinGroup(result);
                    IsOpen = true;
                    callback(true);
                }, null);

            }
            catch
            {
                callback(false);
            }
        }
Beispiel #6
0
 public MulticastUdpSocket(int localPort)
 {
     _UdpClient = CreateMulticastClientAndJoinGroup(SsdpConstants.MulticastLocalAdminAddress, localPort);
 }
Beispiel #7
0
        private static UdpAnySourceMulticastClient CreateMulticastClientAndJoinGroup(string ipAddress, int localPort)
        {
            var retVal = new UdpAnySourceMulticastClient(IPAddress.Parse(ipAddress), localPort);

            var signal = new System.Threading.ManualResetEvent(false);
            try
            {
                retVal.BeginJoinGroup(
                    (joinResult) =>
                    {
                        retVal.EndJoinGroup(joinResult);
                        retVal.MulticastLoopback = true;
                        retVal.SendBufferSize = retVal.ReceiveBufferSize = SsdpConstants.DefaultUdpSocketBufferSize;

                        signal.Set();
                    }, null);

                signal.WaitOne();
            }
            finally
            {
                signal.Dispose();
            }
            return retVal;
        }
 public void initialise()
 {
     _client = new UdpAnySourceMulticastClient(IPAddress.Parse(_groupAddress), _port);
     _receiveBuffer = new byte[MAX_MESSAGE_SIZE];
 }
Beispiel #9
0
        /// <summary>
        /// Create a new UdpAnySourceMulticastClient instance and join the group.
        /// </summary>
        private void Join()
        {
            _logger.Trace("Joining multicast group");

            // Create the UdpAnySourceMulticastClient instance using the defined
            // GROUP_ADDRESS and GROUP_PORT constants. UdpAnySourceMulticastClient is a
            // client receiver for multicast traffic from any source, also known as Any Source Multicast (ASM)
            if (_client == null)
            {
                _client = new UdpAnySourceMulticastClient(IPAddress.Parse(Constants.MulticastGroupAddress), Constants.MulticastGroupPort);
            }

            // Make a request to join the group.
            _client.BeginJoinGroup(
                result =>
                {
                    // Complete the join
                    _client.EndJoinGroup(result);

                    // The MulticastLoopback property controls whether you receive multicast
                    // packets that you send to the multicast group. Default value is true,
                    // meaning that you also receive the packets you send to the multicast group.
                    // To stop receiving these packets, you can set the property following to false
                    _client.MulticastLoopback = false;

                    // Set a flag indicating that we have now joined the multicast group
                    _joined = true;

                    // broadcast
                    BroadcastToServer();
                }, null);
        }
Beispiel #10
0
        private void CleanUp()
        {
            _logger.Trace("Cleaning up");

            _receiving = false;
            _joined = false;

            if (_client != null)
            {
                _client.Dispose();
                _client = null;
            }
        }
 public MDnsClient(IPEndPoint endpoint)
 {
     local = endpoint;
     client = new UdpAnySourceMulticastClient(endpoint.Address, endpoint.Port);
     receiver = new Thread(StartReceiving);
 }