SocketExtensionsSetKeepAliveValues Method

Enables or disables the per-connection setting of the TCP keep-alive option which specifies the TCP keep-alive timeout and interval used for TCP keep-alive packets on the source Socket.

Definition

Namespace: DevCase.Extensions.SocketExtensions
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[EditorBrowsableAttribute(EditorBrowsableState.Always)]
public static void SetKeepAliveValues(
	this Socket socket,
	bool enable,
	int timeout,
	int interval = 1000
)

Parameters

socket  Socket
The source Socket.
enable  Boolean
Enable or disable the TCP keep-alive option.
timeout  Int32
The time, in milliseconds, to keep the TCP connection alive since data was last sent.
interval  Int32  (Optional)
The interval, in milliseconds, at which keep-alive packets are sent.

Default value is: 1000 (1 second).

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Socket. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

For more information on the keep-alive option, see section 4.2.3.6 on the Requirements for Internet HostsCommunication Layers specified in RFC 1122 available at the IETF website: https://www.ietf.org/rfc/rfc1122.txt

Original C# code: https://stackoverflow.com/a/39664592/1248295

See Also