Example #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();
        }
Example #2
0
        public KnxConnectionConfiguration(string host, int port)
        {
            Host = host;
            Port = port;

            IpAddress = null;
            try
            {
                IpAddress = IPAddress.Parse(host);
            }
            catch
            {
                try
                {
                    IpAddress = DnsM.GetHostAddress(host);
                }
                catch (Exception)
                {
                    throw new InvalidHostException(host);
                }
            }

            if (IpAddress == null)
            {
                throw new InvalidHostException(host);
            }

            EndPoint = new IPEndPoint(IpAddress, port);
        }