Kenneth,
 
You are correct, I am using the underlying api to send characters and get responses. My test code listed below pretty much sums it up - the only other key method call is sendKeys in the Screen5250 class (reference obtained from Session5250.getScreen() ) and I've built a number of convienience methods similar to the waitForTextInScreen listed below - all built around Screen5250.getScreenAsChars().
 
With respect to your question about whether the connections are actually being terminated - any suggestions on how to verify that would be appreciated. I do not have anything but user interface access to the AS400 machine I am accessing. I did run lsof while my process was running which will show file descriptors and connections as they are being made and dropped - it looked to me that the sockets were going away as expected and I never had a problem getting a new socket - but the input stream was at an end of file after a number of successful connections. The error message was being generated by the tnvt.readNegotiations method as a result of receiving a -1 from bin.read()
 
As for my original problem, I finally came to roughly the conclusion you outlined here - it is the fault of the Sun 1.3.1_08 jvm running on Linux (I modified several things in the TN5250J codebase to move backwards to 1.3 because an upgrade at this time would just be too involved). Although, I did do a quick upgrade to 1.4 with just my test class to see if it would relieve the problem and it did not - made it worse if anything. I took this back to my client and managed to find a Sun box to run on - thus avoiding the problem. I will cycle back around when things ease up a little.
Test code is listed below for reference, but like I say, it's a non issue at this point and I don't think the fault lies within the TN5250J codebase. I really appreciate your response.
 
Regards,
Tara
 
Test code:
 
import org.tn5250j.beans.ProtocolBean;
import org.tn5250j.Session5250;
import org.tn5250j.framework.tn5250.Screen5250;
import org.apache.log4j.BasicConfigurator;
 
public class My5250Test {
  private Session5250 session;
  private ProtocolBean pb;
  private int lenScreen;
  private Screen5250 screen;

  My5250Test() throws Exception {
    BasicConfigurator.configure();
    ProtocolBean pb = new ProtocolBean("TestConnect", "TestConnect");
    pb.setHostName("<your host here...>");
    for (int n=0; n<=200;n++) {
      session = pb.getSession();
      screen = session.getScreen();
      if (!session.isConnected()) {
        System.out.println("connecting - n = " + n);
        pb.connect();
        waitForTextInScreen("Password", 5000);
      }
      if (session.isConnected()) {
        session.disconnect();
        System.out.println("Moving on...");
      }
      else {
        System.out.println("connection failed!");
      }
    }
  }

  public void waitForTextInScreen(String searchString, int timeout) throws Exception {
    int increments = timeout/200;
    int i = 0;
    boolean found = false;
    char[] screenChars = null;
    String screenString = null;
    while (i <= increments && !found) {
      screenChars = screen.getScreenAsChars();
      screenString = new String(screenChars);
      if (screenString.indexOf(searchString) >= 0) {
        found = true;
      }
      else {
        i++;
        waitFor(200);
      }
    }
    if (found) {
      //a little extra time to allow the screen to finish loading - will save a lot of grief
      waitFor(200);
    }
    else {
      //throw timeout exception
    }
  }

  public void waitFor(int time) {
    try {
          Thread.sleep(200);
        }
        catch (InterruptedException ex) {}
  }

  public static void main(String[] args) {
    try {
      My5250Test myTest = new My5250Test();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}
 
 
 
 
 
Message: 1
Date: Mon, 14 Mar 2005 09:18:24 +0100
From: Kenneth Pouncey <[EMAIL PROTECTED]>
To: tn5250j-general@lists.sourceforge.net
Subject: Re: [Tn5250j-general] IOException on Linux
Reply-To: tn5250j-general@lists.sourceforge.net

Roy

I think here Tara is using the underlying api for the tn5250j project in a
program to do a signon and then execute the commands she needs. She can then
select what to do by reading the responses back from the screens and checking
for specific data. Kind of like what Patrick was doing with his printer manager.

Probably a little more involved than that but the concept is the same. I do
believe there is sample code out there in the project cvs that shows this being
done.

Tara

> > I've written a little test code that simply connects and signs in then
> > disconnects repeatedl y. Once the exception occurs, the process is
> > unsuccessful in establishing any more connections. However, I can
> > restart my test app and it will connect successfully for a period of
> > time (typically 50-60 times though I've seen as low as 10) and then
> > quit again.

I am not sure about this problem could you send me your code bit and I can maybe
test it. You mention that it works on a sun system without a hitch so can not
think it is anything with the code off the top of my head. Are the actual
connections from the linux system being terminated? I had a problem with this
in an older, 1.3.x, linux jdk from sun where when you tell the connection to
disconnect the jvm actually left it lingering out there. Can not remember the
exact details but once these connections were used up you would have to wait for
these lingering connections to actually time out to become ready again.

If you can also post the exact error message coming back that might help as well.

This is off the top of my head though and am thinking you are getting a "can not
allocate socket" error as if the route to the system is not there when
specifying a wrong ip address.

Regards

Kenneth

Quoting rd <[EMAIL PROTECTED]>:

> Tara --
>
> I am rather interested in your "headless" project. How have you
> implemented the new UI/Rendering application to replace the "green
> screen" that you are 'scraping'?
>
> We are dealing with this issue at my office. As a long time tn5250j
> user (on windoz) I would like to consider the approach you have taken.
>
> Is the UI/rendering application proprietary or OSS?
>
> -rdg
>
>
> On Wed, 2005-03-09 at 09:17 -0800, Tara Hunter wrote:
> > Hi guys,
> >
> > I'm really glad this list is showing renewed signs of life!
> > < BR>> > I pulled the restructured codebase from CVS and created a handful of
> > helper methods for supporting a headless data stream interface (okay,
> > okay, screen scraping...). It's been in production since the first of
> > the year and has run without a hitch on a Sun platform for a couple of
> > months.
> >
> > Recent developments have prompted a move to a Linux environment (suse
> > 9) and now the fun begins...
> >
> > I'm getting an IOException thrown in the readNegotiations method of
> > the tnvt class right after the socket connection is established. The
> > log message says the connection is closed but from browsing the code
> > it appears it is really the connections input stream (bin) that is
> > either closed or simply doesn't have any data.
> >
> > I've written a little test code that simply connects and signs in then
> ; > disconnects repeatedly. Once the exception occurs, the process is
> > unsuccessful in establishing any more connections. However, I can
> > restart my test app and it will connect successfully for a period of
> > time (typically 50-60 times though I've seen as low as 10) and then
> > quit again.
> >
> > Because of the architecture and use of my application, I need to be
> > able to connect repeatedly through out the day. I suspect this has
> > something to do with the differences in the way Linux is allocating
> > resources - though I've looked at the socket connections using lsof
> > and it appears they are coming and going as expected.
> >
> > I'm sort of at a loss here and am hoping perhaps one of you has some
> > ideas or suggestions.
> >
> > Regards,
> > Tara
> >


Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!

Reply via email to