Question

I'm tried to get AS400 TCP Connection Status. but i'm failed :( can anyone help me to do this. i'm new to JT400 java development. please help me friends.

  1. i want to get IP address of a job
  2. i want to get TCP Connection Status using that (1) IP address.

Please help me Thank you!

Edit :

i got this class

com.ibm.as400.util.commtrace.TCPHeader

It's return this informations

getACKFlag()
getAckNum()
getCheckSum()
getCWRFlag()
getDataOffset()
getDstPort() ..etc

now i want to get this informations. its mean, how to get TCP status using this class.

Please help me

Thank You

Was it helpful?

Solution 2

The commtrace classes are not real-time. They use a trace file which was created on the IBM i server at some earlier time. In order to create that trace file, see the Javadoc for com.ibm.as400.util.commtrace.CommTrace Basically you will need to run the IBM i commands STRCMNTRC, ENDCMNTRC and DMPCMNTRC. Then use commtrace.CommTrace to create a trace file formatted so that the other commtrace classes can read it.

EDIT: Add code snippet from commtrace.Format Javadoc

import java.util.*;
import com.ibm.as400.access.*;
import com.ibm.as400.util.commtrace.*;

public class TestCommTrace {
    public static void main(String[] args) {

try {
 Format f = new Format("/buck/linetrace");

 FormatProperties fmtprop = new FormatProperties();
 f.setFilterProperties(fmtprop); // Sets the filtering properties for this Format

 f.formatProlog(); // Format the prolog
 Prolog pro = f.getProlog();    
 System.out.println(pro.toString());

 if(!pro.invalidData()) { // This is not a valid trace
         Frame rec; 
         while((rec=f.getNextRecord())!=null) { // Get the records
                System.out.print("Frame " + rec.getRecNum().toString()); // Print out the Frame Number
                System.out.println(" time " + rec.getTime().toString()); // Print out the time
                IPPacket p = rec.getPacket(); // Get this records packet
                Header h = p.getHeader(); // Get the first header
                if(p.getType()==IPPacket.IP4) { // If IP4 IPPacket
                        if(h.getType()==Header.IP4) { // If IP4 Header
                                IP4Header ip4 = (IP4Header) h; // Cast to IP4 so we can access methods
                                System.out.println(h.getName()); // Print the name
                                System.out.println("IP4 src:"+ip4.getSrcAddr() + " dst:" + ip4.getDstAddr());
                                System.out.println(ip4.printHexHeader()); // Print the header as hex 
                                // Print a string representation of the header.
                                System.out.println(ip4.toString()); // hex string
                                //System.out.println(ip4.toString(fmtprop)); // very detailed
                                while((h=h.getNextHeader())!=null) { // Get the rest of the headers
                                        if(h.getType()==Header.TCP) { // If its a TCP header
                                                TCPHeader tcp = (TCPHeader) h; // Cast so we can access methods
                                                System.out.println("TCP src:" + tcp.getSrcPort() + " dst:" + tcp.getDstPort() + " checksum:" + tcp.getCheckSum()); 
                                                System.out.println(tcp.toString());  // hex string
                                                //System.out.println(tcp.toString(fmtprop));  // very detailed

                                        } else if(h.getType()==Header.UDP) { // If its a UDP header
                                                UDPHeader udp = (UDPHeader) h; // Cast so we can access methods
                                                System.out.println("UDP src:" + udp.getSrcPort() + " dst:" + udp.getDstPort()); 
                                                System.out.println(udp.toString());
                                        }
                                }
                        }
                }
         } 

 f.close();
 }      
    } catch (Exception e) {
      e.printStackTrace();
    }
}

}

EDIT: Some more detailed information

1) On the IBM system, someone with special permission must run STRCMNTRC and collect communications trace information. This trace file contains all of the TCP packets that flowed between the IBM system and the outside world. For example, if the trace runs for an hour, it will collect every packet the system sent and received during that hour. The trace data is stored in a format that is special and can not be directly read.

2) To make the trace data readable, use the DMPCMNTRC command. This will create a flat text stream file out of the trace data. This data needs to get to your PC so that the com.ibm.as400.util.commtrace classes can work on it.

3) On your PC, run com.ibm.as400.util.commtrace.CommTrace. This will create a file in a simple text form that com.ibm.as400.util.commtrace can process. I put mine in /buck/linetrace. It is important to understand that there are hundreds or thousands of packets in this log, and every one of them has the information you ask about in the question. There is not one single ACK flag, there are many hundreds of them. In order to understand what is happening, your program will need to read a packet, get the header, then the status, get the data and then read the next packet, and the next and the next, all the way through them all.

4) In order to filter by IP address, you can either use setFilterProperties() or have your code check the IP addresses in each packet header and only process the headers you want to.

It is important to understand that the 'status' you are looking for is not a property of an IP address, it is a property of a TCP packet. There is no way to ask the system for the ACK flag of an IP address because there is no such property to be returned. The only way to get these things is to record them at the instant the packet is read or written by the system.

I would be very surprised if you really need these flags; almost no one does. Usually, 'connection status' means a way to determine if the machine is running or not. ping is the typical way to answer that question, but not all machines will answer a ping. For those machines, the best way is to try to connect to the machine and port you want to test.

OTHER TIPS

To get the IP address of a job:

System.out.println("IP address " + job.getValue(job.CLIENT_IP_ADDRESS));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top