Export (0) Print
Expand All

ServicePointManager::SetTcpKeepAlive Method

Enables or disables the keep-alive option on a TCP connection.

Namespace:  System.Net
Assembly:  System (in System.dll)

public:
static void SetTcpKeepAlive(
	bool enabled, 
	int keepAliveTime, 
	int keepAliveInterval
)

Parameters

enabled
Type: System::Boolean
If set to true, then the TCP keep-alive option on a TCP connection will be enabled using the specified keepAliveTime and keepAliveInterval values.
If set to false, then the TCP keep-alive option is disabled and the remaining parameters are ignored.
The default value is false.
keepAliveTime
Type: System::Int32
Specifies the timeout, in milliseconds, with no activity until the first keep-alive packet is sent.
The value must be greater than 0. If a value of less than or equal to zero is passed an ArgumentOutOfRangeException is thrown.
keepAliveInterval
Type: System::Int32
Specifies the interval, in milliseconds, between when successive keep-alive packets are sent if no acknowledgement is received.
The value must be greater than 0. If a value of less than or equal to zero is passed an ArgumentOutOfRangeException is thrown.

ExceptionCondition
ArgumentOutOfRangeException

The value specified for keepAliveTime or keepAliveInterval parameter is less than or equal to 0.

An application can request that a TCP/IP provider enable the use of keep-alive packets on a TCP connection. The default is that the use of keep-alive packets on a TCP connection is disabled.

The default settings when a TCP socket is initialized sets the keep-alive timeout to 2 hours and the keep-alive interval to 1 second. The keepAliveTime parameter specifies the timeout, in milliseconds, with no activity until the first keep-alive packet is sent. The keepAliveInterval parameter specifies the interval, in milliseconds, between when successive keep-alive packets are sent if no acknowledgement is received. The number of keep-alive probes cannot be changed and is set to 10.

If a TCP connection is dropped as the result of keep-alives, a SocketError of NetworkReset is returned to any calls in progress on the socket, and any subsequent calls will fail with a SocketError of NotConnected.

.NET Framework

Supported in: 4, 3.5 SP1, 3.0 SP2, 2.0 SP2

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft