| Visual Basic (Declaration) | |
|---|---|
<CategoryAttribute("Socket Options")> <DescriptionAttribute("Gets or Sets the value of the socket's KeepAlive option.")> <DefaultValueAttribute()> Public Property KeepAlive As Boolean | |
| Visual Basic (Usage) | Copy Code |
|---|---|
Dim instance As Tcp Dim value As Boolean instance.KeepAlive = value value = instance.KeepAlive | |
| C# | |
|---|---|
[CategoryAttribute("Socket Options")] [DescriptionAttribute("Gets or Sets the value of the socket's KeepAlive option.")] [DefaultValueAttribute()] public bool KeepAlive {get; set;} | |
| Managed Extensions for C++ | |
|---|---|
[CategoryAttribute("Socket Options")] [DescriptionAttribute("Gets or Sets the value of the socket's KeepAlive option.")] [DefaultValueAttribute()] public: __property bool get_KeepAlive(); public: __property void set_KeepAlive( bool value ); | |
| C++/CLI | |
|---|---|
[CategoryAttribute("Socket Options")] [DescriptionAttribute("Gets or Sets the value of the socket's KeepAlive option.")] [DefaultValueAttribute()] public: property bool KeepAlive { bool get(); void set ( bool value); } | |
Property Value
true if packets are to be sent during inactive periods; otherwise, false. The default value is false.| Visual Basic | Copy Code |
|---|---|
' Disable UI events. Tcp1.DoEvents = False ' Enable KeepAlive socket option Tcp1.KeepAlive = True ' Disable use of Nagle's Algoritm Tcp1.NoDelay = True ' Read urgent data as normal in-line data. Tcp1.OutOfBandInline = True ' Allow addresses to be reused Tcp1.ReuseAddress = True ' Connect Tcp1.Connect("atropos", 7) ' Send data Tcp1.Send("test") ' Receive response Dim seg As Segment = Tcp1.Receive() | |
| C# | Copy Code |
|---|---|
// Disable UI events. tcp1.DoEvents = false; // Enable KeepAlive socket option tcp1.KeepAlive = true; // Disable use of Nagle's Algoritm tcp1.NoDelay = true; // Read urgent data as normal in-line data. tcp1.OutOfBandInline = true; // Allow addresses to be reused tcp1.ReuseAddress = true // Connect tcp1.Connect("atropos", 7); // Send data tcp1.Send("test"); // Receive response Segment seg = tcp1.Receive(); | |
When a connection is inactive (data is not being sent or received for a period of time), setting Tcp.KeepAlive to true causes the underlying Socket of the Tcp component to probe the other end of a connection when it has been idle for an allotted amount of time (usually 2 hours).
This property can be used to ensure a connection reset indication occurs during periods of inactivity.
The timeout before keepalives are sent and the interval between keepalive transmissions can be set by editing the system's registry.
1. Find the registry key.
For Windows 95/98/ME:
[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP]
For other Operating Systems:
[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters]
2. Create a DWORD value "KeepAliveTime" and set it to the number of milliseconds to wait before sending keep alive packets (the default is 2 hours - 7,200,000 milliseconds).
3. Create a DWORD value (or string value for Windows 98) "KeepAliveInterval" and set it to the time in milliseconds between retransmissions of keepalives, once the KeepAliveTime has expired (the default is 1 second - 1000 milliseconds).
4. Restart Windows for the change to take effect.
Target Platforms: Microsoft .NET Framework 2.0
Copy Code