Beispiel #1
0
        private static int SetKeepAliveValues
        (
            System.Net.Sockets.Socket Socket,
            bool On_Off,
            uint KeepaLiveTime,
            uint KeepaLiveInterval
        )
        {
            int Result = -1;

            unsafe
            {
                TcpKeepAlive KeepAliveValues = new TcpKeepAlive();

                KeepAliveValues.On_Off            = Convert.ToUInt32(On_Off);
                KeepAliveValues.KeepALiveTime     = KeepaLiveTime;
                KeepAliveValues.KeepALiveInterval = KeepaLiveInterval;

                byte[] InValue = new byte[12];

                //for (int I = 0; I < 12; I++)
                //InValue[I] = KeepAliveValues.Bytes[I];
                Array.Copy(KeepAliveValues.ToArray(), InValue, InValue.Length);

                Result = Socket.IOControl(System.Net.Sockets.IOControlCode.KeepAliveValues, InValue, null);
            }

            return(Result);
        }
Beispiel #2
0
        /// <summary>
        /// Sets the keep alive values.
        /// </summary>
        /// <param name="state">if set to <c>true</c> [state].</param>
        /// <param name="keepAliveTime">The keep alive time.</param>
        /// <param name="keepAliveInterval">The keep alive interval.</param>
        /// <returns></returns>
        public int SetKeepAliveValues(bool state, int keepAliveTime, int keepAliveInterval)
        {
            if (keepAliveTime < 1000)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException("keepAliveTime");
            }
            if (keepAliveInterval < 1000)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException("keepAliveInterval");
            }

            TcpKeepAlive keepAlive = new TcpKeepAlive();

            keepAlive.State             = Convert.ToUInt32(state);
            keepAlive.KeepAliveTime     = Convert.ToUInt32(keepAliveTime);
            keepAlive.KeepAliveInterval = Convert.ToUInt32(keepAliveInterval);

            return(mSocket.IOControl(IOControlCode.KeepAliveValues, keepAlive.ToArray(), null));
        }