ctors.net
Blog tvlooy

Keeping 5250 Alive

IBM i | June 11, 2011

This article was published at IT Jungle.

Some time ago, we had problems with 5250 Client Access sessions being reset. It seemed that these connections were travelling over a VPN that got disconnected after being idle for a while. Because we were not in charge of the VPN, I used TCP keepalive as a workaround for this problem.

Keepalive

A TCP connection can set the SO_KEEPALIVE option with the setsockopts() system call. When the TCP connection is idle for a specified period of time, a keepalive packet will be sent to keep the connection open. (In practice, this keepalive packet is a request for acknowledgement of the previous packet.) Most programming languages provide a library routine to activate the keepalive option. For example, Java provides the setKeepAlive() method, which can be invoked after socket construction.

There are three parameters that can be configured for keepalive messages. On a Windows machine, these are registry values in HKLM\SYSTEM\CurrentControlSet\Services\TcpIp\Parameters. KeepAliveInterval (default 1 second), KeepAliveTime (default 2 hours) and TcpMaxDataRetransmission (default 5 seconds). On a Linux machine these are sysctl values in net.ipv4 (or procfs in /proc/sys/net/ipv4), tcp_keepalive_intvl (default 75s), tcp_keepalive_time (default 2h), and tcp_keepalive_probes (default 9).

TCP keepalive messages are described in RFC1122. The RFC also points out some disadvantages of sending keepalive messages.

5250 Keepalive

It is possible to activate keepalive messages on the 5250 emulator. The startup file for a System i connection (.WS file) must be edited with a text editor. These files reside by default in C:\Program Files\IBM\Client Access\Emulator\Private. Below the [Telnet5250] option you add the option KeepAlive=Y. This is enough to activate keepalive messages on a 5250 session.

The IBM Client Access suite delivers a command line tool, CWBCOPWR, that can configure some of the keepalive parameters. For example, to set KeepAliveTime to 10 seconds and KeepAliveInterval to 1 second, use the command cwbcopwr/MKA:1,10.