public void ToBytes_should_return_expected_result(uint onOff, uint keepAliveTime, uint keepAliveInterval, byte[] expectedResult)
        {
            var subject = new KeepAliveValues
            {
                OnOff             = onOff,
                KeepAliveTime     = keepAliveTime,
                KeepAliveInterval = keepAliveInterval
            };

            var result = subject.ToBytes();

            result.Should().Equal(expectedResult);
        }
        private Socket CreateSocket(EndPoint endPoint)
        {
            var addressFamily = endPoint.AddressFamily;

            if (addressFamily == AddressFamily.Unspecified || addressFamily == AddressFamily.Unknown)
            {
                addressFamily = _settings.AddressFamily;
            }

            var socket          = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp);
            var keepAliveValues = new KeepAliveValues
            {
                OnOff             = 1,
                KeepAliveTime     = 300000, // 300 seconds in milliseconds
                KeepAliveInterval = 10000   // 10 seconds in milliseconds
            };

            socket.IOControl(IOControlCode.KeepAliveValues, keepAliveValues.ToBytes(), null);

            return(socket);
        }
        private Socket CreateSocket(EndPoint endPoint)
        {
            var addressFamily = endPoint.AddressFamily;

            if (addressFamily == AddressFamily.Unspecified || addressFamily == AddressFamily.Unknown)
            {
                addressFamily = _settings.AddressFamily;
            }

            var socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp);

            // not all platforms support IOControl
            try
            {
                var keepAliveValues = new KeepAliveValues
                {
                    OnOff             = 1,
                    KeepAliveTime     = 300000, // 300 seconds in milliseconds
                    KeepAliveInterval = 10000   // 10 seconds in milliseconds
                };
                socket.IOControl(IOControlCode.KeepAliveValues, keepAliveValues.ToBytes(), null);
            }
            catch (PlatformNotSupportedException)
            {
                // most platforms should support this call to SetSocketOption, but just in case call it in a try/catch also
                try
                {
                    socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
                }
                catch (PlatformNotSupportedException)
                {
                    // ignore PlatformNotSupportedException
                }
            }

            return(socket);
        }