Search code examples
tcpportibm-midrangerpg

Capture port information on iSeries programmically


Currently we receive on port 9020 from a client. That client uses port switching on their end and sometimes we wind up with multiple "Established" connections on the one port - all with different remote ports. We can manually end each established connection and our job will connect again after a few seconds. We can also run ENDTCPCNN for each remote port listed. We are looking for a way to programmatically see if there are multiple remote ports connected to the local port and if so end the established connections (while leaving the Listener running). Does anyone know of a way to get the information?


Solution

  • To answer your question, assuming you are on a supported version of the OS, take a look at the QSYS2.NETSTAT_INFO SQL view.

    select local_port, remote_port, protocol, tcp_state, idle_time, network_connection_type
     from qsys2.netstat_info
    where local_port = 9020;
    

    Otherwise, you'd need to use the List Network Connections and Retrieve Network Connection Data APIs yourself.

    But are you sure you need to do this? Sounds like the client is leaving the connection open for re-use. That's a good thing for performance. You server code should be automatically timing out and closing idle connections.