Пример #1
0
        /// <summary>
        ///     Start the connection
        /// </summary>
        public override void Connect()
        {
            Logger.Info(ClassName, "KNXLib connecting...");

            try
            {
                if (_udpClient != null)
                {
                    try
                    {
                        _udpClient.Close();

                        if (_udpClient.Client != null)
                        {
                            _udpClient.Client.Dispose();
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Error(ClassName, e);
                    }
                }

                _udpClient = new UdpClient(_localEndpoint)
                {
                    Client =
                    {
                        // DontFragment = true, // Not Supported on macOS/Linux
                        // SendBufferSize = 0, // Not Supported on macOS
                        ReceiveTimeout = stateRequestTimerInterval * 2
                    }
                };
            }
            catch (SocketException ex)
            {
                throw new ConnectionErrorException(ConnectionConfiguration, ex);
            }

            if (KnxReceiver == null || KnxSender == null)
            {
                KnxReceiver = new KnxReceiverTunneling(this, _udpClient, _localEndpoint);
                KnxSender   = new KnxSenderTunneling(this, _udpClient, RemoteEndpoint);
            }
            else
            {
                ((KnxReceiverTunneling)KnxReceiver).SetClient(_udpClient);
                ((KnxSenderTunneling)KnxSender).SetClient(_udpClient);
            }

            KnxReceiver.Start();

            try
            {
                ConnectRequest();
            }
            catch (Exception e)
            {
                Logger.Error(ClassName, e);
            }
        }
Пример #2
0
        /// <summary>
        ///     Start the connection
        /// </summary>
        public override void Connect()
        {
            try
            {
                if (_udpClient != null)
                {
                    try
                    {
                        _udpClient.Close();
                        _udpClient.Client.Dispose();
                    }
                    catch
                    {
                        // ignore
                    }
                }

                _udpClient = new UdpClient(_localEndpoint)
                {
                    Client = { DontFragment = true, SendBufferSize = 0 }
                };
            }
            catch (SocketException ex)
            {
                throw new ConnectionErrorException(ConnectionConfiguration, ex);
            }

            if (KnxReceiver == null || KnxSender == null)
            {
                KnxReceiver = new KnxReceiverTunneling(this, _udpClient, _localEndpoint);
                KnxSender   = new KnxSenderTunneling(this, _udpClient, RemoteEndpoint);
            }
            else
            {
                ((KnxReceiverTunneling)KnxReceiver).SetClient(_udpClient);
                ((KnxSenderTunneling)KnxSender).SetClient(_udpClient);
            }

            KnxReceiver.Start();

            try
            {
                ConnectRequest();
            }
            catch
            {
                // ignore
            }
        }
Пример #3
0
        /// <summary>
        ///     Start the connection
        /// </summary>
        public override void Connect()
        {
            try
            {
                if (_udpClient != null)
                {
                    try
                    {
                        _udpClient.Close();
                        _udpClient.Client.Dispose();
                    }
                    catch
                    {
                        // ignore
                    }
                }

                _udpClient = new UdpClient(_localEndpoint)
                {
                    Client = {DontFragment = true, SendBufferSize = 0}
                };
            }
            catch (SocketException ex)
            {
                throw new ConnectionErrorException(ConnectionConfiguration, ex);
            }

            if (KnxReceiver == null || KnxSender == null)
            {
                KnxReceiver = new KnxReceiverTunneling(this, _udpClient, _localEndpoint);
                KnxSender = new KnxSenderTunneling(this, _udpClient, RemoteEndpoint);
            }
            else
            {
                ((KnxReceiverTunneling) KnxReceiver).SetClient(_udpClient);
                ((KnxSenderTunneling) KnxSender).SetClient(_udpClient);
            }

            KnxReceiver.Start();

            try
            {
                ConnectRequest();
            }
            catch
            {
                // ignore
            }
        }