Determine TCP port used by a connection.

95 pts.
Tags:
CL
CLLE
iSeries networking
RPGLE
TCP
We have an application that has our iSeries(AS/400) connect to a remote IP address and port. If we have to end the application and restart it (IPL, error, end/start subsystem) the iSeries keeps the connection open. AFter the application is restarted, the TCP connections show two connections to the remote IP, and the application does not transfer data on the new(second) connection. I have looked at the ENDTCPCNN command, and it requires the local IP address and port. Is there any way to capture this information in a program? We would like to automate the ENDTCPCNN command so the operators do not need to look up the local port each time.

Answer Wiki

Thanks. We'll let you know when a new response is added.

Interesting. Most TCP stacks should time out and close a connection after a period of non-activity. You don’t say what the device is at the other end of the connection and if you have control of it. I can’t answer AS/400 specifics but if the remote device is a Windows host then you can go to a command prompt and type <b>netstat -an</b>. This command will give you a list of the local addresses/ports and remote addresses/ports and the current state of those connections. There is a similar command on AS/400 and some details can be found <a href=”http://search400.techtarget.com/tip/0,289483,sid3_gci1132847,00.html”>here</a>. Maybe <a href=”http://home.columbus.rr.com/jbmmdietz/nstat.html”>this utility</a> would help.

Discuss This Question: 6  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Gilly400
    Hi, If you're IPL'ing the AS400, then it's not the AS400 that's keeping the connection open. If you IPL, then everthing is shutdown and restarted, including all communications. When the AS400 is restarted, then maybe it creates a new connection, but the old connection should be gone, unless the machine at the other end re-opens it. I suggest you check whatever is on the other end of your connection. Regards, Martin Gilbert.
    23,730 pointsBadges:
    report
  • LHrabar
    The device os a small TCP/IP-> Com port converter box which listens for a connection. The iSeries connects to this converter using TCP/IP. If we end the program that connects, or the subsystem that it runs in, and then restart the process the iSeries does not drop the connection. It will if we let it time out, but most of the time the stop/start happens within a few seconds. I would like to add an ENDTCPCNN command to make sure that the connection is closed, but the command requires the local port number. The connection is setup to connect to port yyyy on the converter. The iSeries will use any available port. I am looking for a way to get the local port number in a program. I know I can use netstat/wrktcpsts to find the port, but I am trying to automate the process so the operators do not have to find the local port number and manually enter the endtcpcnn command.
    95 pointsBadges:
    report
  • mcl
    Unfortunately, the ENDTCPCNN command exists so that you can limit authority to ending connections through NETSTAT. The connections should time out and drop, but other than that I think you can only end the connection using NETSTAT. Take option #3, scroll down through the list and end with option #4. Regards Mike
    2,740 pointsBadges:
    report
  • LHrabar
    Thanks for all the answers. What I am looking to do is to not have the operators, or anyone, have to lookup the port number and end the connection (using ENDTCPCNN ro NETSTAT/Opt#3/Opt#4). I would like to have a program retrieve the local port number and end the connection. No manual intervention needed.
    95 pointsBadges:
    report
  • bvining
    You have a few options here. If you have the source for the application program you could: 1. Use the bind() API (long name of Set Local Address for Socket) to turn off the port selection by the system. Just use a fixed port number and that's what you'll cancel on. 2. After you have established the connection use the getsockname() API (long name of Get Local Address of Socket). Given the socket desriptor the API will return to you the local address. This local address includes the port number. You could write the port number to a *DTAARA and use this stored value later, if needed, to end the connection. Using this approach I would lean towards clearing the value upon a successful close of the connection. If you don't have the source for the application program then you can get at the data that NetStat drives off of with the QtocLstNetCnn API (long name of List Network Connections). This API also returns port information. I hope this helps, Bruce Vining http://www.brucevining.com/
    6,465 pointsBadges:
    report
  • LHrabar
    Thanks bvining, After adding the bind call to my program, I was able to control the local port number. Adding the ENDTCPCNN command was just as easy. I have tested the ENDSBS/STRSBS a few times, and it works great. Thanks to all who responded, Len
    95 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following