How To Test TCP KeepAlive?
This page answers questions like these:
- How do I know if KeepAlive is functioning?
- How to know if KeepAlive is working properly?
- How do I verify that KeepAlive is working?
- How do I test KeepAlive?
Related Links:
What Is TCP KeepAlive?
How To Use TCP KeepAlive?
What Are The Default TCP KeepAlive Parameters?
TCP KeepAlive Parameter Ranges
Ephemeral Ports
How do I Know if KeepAlive is Working?
- For the purpose of unit testing your KeepAlive code, you may want to connect to your server’s listening port using telnet as the client. You can do this in one of the following ways:
- You can run telnet on the same machine as the server as follows:
$ telnet 127.0.0.1 SERVERPORT
- You can run telnet on a different machine from the server as follows:
(Note that SERVER can be either the server name or the server IP address.)
$ telnet SERVER SERVERPORT
- After the connection is established, you can see whether KeepAlive is enabled by running netstat on the server machine as follows:
$ netstat -a -n -o | grep -w :SERVERPORT
tcp 0 0 0.0.0.0:SERVERPORT 0.0.0.0:* LISTEN off (0.00/0/0)
tcp 0 0 CLIENTIP:CLIENTPORT SERVERIP:SERVERPORT ESTABLISHED off (0.00/0/0)
tcp 0 0 SERVERIP:SERVERPORT CLIENTIP:CLIENTPORT ESTABLISHED keepalive (897.46/0/0)
- The output of netstat shows you 2 or 3 lines which are explained as follows:
- The LISTEN line is your server program listening on the port SERVERPORT again after accepting the first client connection.
- The ESTABLISHED off line is the client-side of the socket connection (which most likely has KeepAlive switched off). [This line will only be present if the client is running on the same machine as the server.]
- The ESTABLISHED keepalive line is the server-side of the socket connection (which has KeepAlive switched on if your server KeepAlive code is working correctly). The first number in brackets, which in this example is 897.46, is the number of seconds left before a KeepAlive probe will be sent. If you repeatedly run the above netstat command, you will see this number getting smaller and smaller.
- SERVERIP is the server machine’s IP address.
- SERVERPORT is the port being listened to on the server machine.
- CLIENTIP is the client machine’s IP address.
- CLIENTPORT is the port being used on the client machine. This is an
ephemeral port.
Related Links:
What Is TCP KeepAlive?
How To Use TCP KeepAlive?
What Are The Default TCP KeepAlive Parameters?
TCP KeepAlive Parameter Ranges
Ephemeral Ports
Home > C++ / C > How To Test TCP KeepAlive?
Tags: verify KeepAlive, verify keep alive, check tcpip keepalive, test tcp keepalive socket, testing KeepAlive, verifying KeepAlive, unit testing KeepAlive, socket, TCP, Transmission Control Protocol, C++, C
Copyright © HelpDoco.com
tcp-keepalive-testing.txt
C++-C/tcp-keepalive-testing-verification.htm
1