Esempio n. 1
0
        /// <summary>
        ///     Start the connection
        /// </summary>
        public override void Connect()
        {
            try
            {
                IEnumerable <IPAddress> ipv4Addresses = DnsM.GetHostAddresses();


                foreach (IPAddress localIp in ipv4Addresses)
                {
                    var client = new UdpClient(new IPEndPoint(localIp, _localEndpoint.Port));
                    _udpClients.Add(client);
                    client.JoinMulticastGroup(ConnectionConfiguration.IpAddress, localIp);
                }
            }
            catch (SocketException ex)
            {
                throw new ConnectionErrorException(ConnectionConfiguration, ex);
            }

            // TODO: Maybe if we have a base Connect helper which takes in a KnxReceiver and KnxSender,
            // we can make the property setters more restricted
            KnxReceiver = new KnxReceiverRouting(this, _udpClients);
            KnxReceiver.Start();

            KnxSender = new KnxSenderRouting(this, _udpClients, RemoteEndpoint);

            Connected();
        }
Esempio n. 2
0
        /// <summary>
        ///     Start the connection
        /// </summary>
        public override void Connect()
        {
            try
            {
                IEnumerable<IPAddress> ipv4Addresses =
                    Dns
                        .GetHostAddresses(Dns.GetHostName())
                        .Where(i => i.AddressFamily == AddressFamily.InterNetwork);

                foreach (IPAddress localIp in ipv4Addresses)
                {
                    var client = new UdpClient(new IPEndPoint(localIp, _localEndpoint.Port));
                    _udpClients.Add(client);
                    client.JoinMulticastGroup(ConnectionConfiguration.IpAddress, localIp);
                }
            }
            catch (SocketException ex)
            {
                throw new ConnectionErrorException(ConnectionConfiguration, ex);
            }

            // TODO: Maybe if we have a base Connect helper which takes in a KnxReceiver and KnxSender,
            // we can make the property setters more restricted
            KnxReceiver = new KnxReceiverRouting(this, _udpClients);
            KnxReceiver.Start();

            KnxSender = new KnxSenderRouting(this, _udpClients, RemoteEndpoint);

            Connected();
        }