How to Check if TCP/IP is Active

Q: How can I check to see if the STRTCP command has been run? I have a
program that runs at start up that needs TCP/IP. How can I wait until
TCP/IP has started to run it?

A: The Retrieve TCP/IP Attributes (QtocRtvTCPA) API can tell you if
TCP/IP is operational. Carsten Flensburg has written a command that
uses this API to check if TCP/IP is operational.

This RTVTCPSTS command will return one of three values. It will return
O if TCP/IP is operational, N if it is not operational, or E if an
error occurs.

For example, the following is a CL program that checks every second to
see if TCP/IP is operational. Once it’s operational, it could run the
program that needs TCP/IP support:


Dcl &TcpSts *Char 1

RtvTcpSts TcpSts( &TcpSts )

If ( &TcpSts *NE 'O' ) Do
DlyJob Dly(1)
GoTo TryAgain

/*-- Run program that needs TCP/IP --*/


You can download the source code for the RtvTcpSts utility from iSeries
Network’s Web site at the following link:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s