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:

Pgm

Dcl &TcpSts *Char 1

TryAgain:
RtvTcpSts TcpSts( &TcpSts )

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

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

EndPgm

You can download the source code for the RtvTcpSts utility from iSeries
Network’s Web site at the following link:
http://www2.systeminetwork.com/noderesources/code/clubtechcode/RtvTcpSts.zip

Leave a Reply

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

WordPress.com Logo

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

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s