J2ME Network Problems, Network Lockup after 13+ GETs

Discussion in 'Java' started by Bill Volk, Jul 2, 2003.

  1. Bill Volk

    Bill Volk Guest

    We have done a series of tests and have determined a failure mode in
    the J2ME HTTP network functionality:

    Nokia 3650
    Firmware: V 2.54, 2-3-2003
    Network: AT&T

    Using the published code from the networking example at:

    http://wireless.java.sun.com/midp/articles/network/

    (Example 3)

    Repeating the connection in a loop we see the following replicable
    behavior:

    1. Network requests work fine till around the 13th interaction.

    2. This request tends to throw an exception. (i.e. unexpected
    end-of-stream encountered)

    3. We believe this exception is caused by a network timeout based on
    our other tests.

    4. The 14th request is then successful but the 15th request also times
    out.

    5. At this point we appear to have lost the ability to do any net
    connection as our 16th, 17th, 18th, 19th, and 20th requests all throw
    exceptions.

    Code Follows:

    package thirdexample;

    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;

    /**
    * An example MIDlet to invoke a CGI script.
    */

    public class ThirdExample extends MIDlet
    {
    private Display display;
    String url = "http://developer.java.sun.com/cgibin/getgrade.cgi?name=182016";
    private Form fForm;

    public ThirdExample()
    {
    display = Display.getDisplay(this);
    }
    /**
    * Initialization. Invoked the MIDlet is activated.
    */
    public void startApp()
    {
    fForm = new Form("Test");
    display.setCurrent(fForm);
    for (int i = 0; i < 20; i++)
    {
    fForm.append("try #" + (i + 1) + ": ");
    try
    {
    long time1 = System.currentTimeMillis();
    getGrade(url);
    long time2 = System.currentTimeMillis();

    fForm.append("(" + (time2 - time1) + " millis)\n");
    }
    catch (IOException e)
    {
    fForm.append(e.getMessage());
    e.printStackTrace();
    }
    }
    }
    /**
    * Pause, discontinue ....
    */
    public void pauseApp() { }
    /**
    * Destroy must cleanup everything.
    */
    public void destroyApp(boolean unconditional) { }
    /**
    * Retrieve a grade....
    */
    void getGrade(String url) throws IOException
    {
    HttpConnection c = null;
    InputStream is = null;
    OutputStream os = null;
    StringBuffer b = new StringBuffer();
    TextBox t = null;

    try
    {
    c = (HttpConnection) Connector.open(url);
    c.setRequestMethod(HttpConnection.GET);
    c.setRequestProperty("IF-Modified-Since",
    "10 Nov 2000 17:29:12 GMT");
    c.setRequestProperty("User-Agent",
    "Profile/MIDP-1.0
    Confirguration/CLDC-1.0");
    c.setRequestProperty("Content-Language",
    "en-CA");
    os = c.openOutputStream();

    /**
    String str = "?idnum=182016";
    byte postmsg[] = str.getBytes();
    for(int i=0;i<postmsg.length;i++) {
    os.writeByte(postmsg);
    }
    os.flush();
    */

    is = c.openDataInputStream();
    int ch;
    while ((ch = is.read()) != -1)
    {
    b.append((char) ch);
    }
    //t = new TextBox("Final Grades", b.toString(), 1024, 0);
    fForm.append(b.toString());
    }
    finally
    {
    if (is != null)
    {
    is.close();
    }
    if (os != null)
    {
    os.close();
    }
    if (c != null)
    {
    c.close();
    }
    }
    //display.setCurrent(t);
    }
    }

    This code has been successfully tested in the emulator.

    Bill Volk
    Teknik Digital Arts
    Bill Volk, Jul 2, 2003
    #1
    1. Advertising

  2. Bill Volk

    Bill Volk Guest

    Note: Have verified this with a commerical application ... WebViewer.

    Bill


    (Bill Volk) wrote in message news:<>...
    > We have done a series of tests and have determined a failure mode in
    > the J2ME HTTP network functionality:
    >
    > Nokia 3650
    > Firmware: V 2.54, 2-3-2003
    > Network: AT&T
    >
    > Using the published code from the networking example at:
    >
    > http://wireless.java.sun.com/midp/articles/network/
    >
    > (Example 3)
    >
    > Repeating the connection in a loop we see the following replicable
    > behavior:
    >
    > 1. Network requests work fine till around the 13th interaction.
    >
    > 2. This request tends to throw an exception. (i.e. unexpected
    > end-of-stream encountered)
    >
    > 3. We believe this exception is caused by a network timeout based on
    > our other tests.
    >
    > 4. The 14th request is then successful but the 15th request also times
    > out.
    >
    > 5. At this point we appear to have lost the ability to do any net
    > connection as our 16th, 17th, 18th, 19th, and 20th requests all throw
    > exceptions.
    >
    > Code Follows:
    >
    > package thirdexample;
    >
    > import java.io.*;
    > import javax.microedition.io.*;
    > import javax.microedition.lcdui.*;
    > import javax.microedition.midlet.*;
    >
    > /**
    > * An example MIDlet to invoke a CGI script.
    > */
    >
    > public class ThirdExample extends MIDlet
    > {
    > private Display display;
    > String url = "http://developer.java.sun.com/cgibin/getgrade.cgi?name=182016";
    > private Form fForm;
    >
    > public ThirdExample()
    > {
    > display = Display.getDisplay(this);
    > }
    > /**
    > * Initialization. Invoked the MIDlet is activated.
    > */
    > public void startApp()
    > {
    > fForm = new Form("Test");
    > display.setCurrent(fForm);
    > for (int i = 0; i < 20; i++)
    > {
    > fForm.append("try #" + (i + 1) + ": ");
    > try
    > {
    > long time1 = System.currentTimeMillis();
    > getGrade(url);
    > long time2 = System.currentTimeMillis();
    >
    > fForm.append("(" + (time2 - time1) + " millis)\n");
    > }
    > catch (IOException e)
    > {
    > fForm.append(e.getMessage());
    > e.printStackTrace();
    > }
    > }
    > }
    > /**
    > * Pause, discontinue ....
    > */
    > public void pauseApp() { }
    > /**
    > * Destroy must cleanup everything.
    > */
    > public void destroyApp(boolean unconditional) { }
    > /**
    > * Retrieve a grade....
    > */
    > void getGrade(String url) throws IOException
    > {
    > HttpConnection c = null;
    > InputStream is = null;
    > OutputStream os = null;
    > StringBuffer b = new StringBuffer();
    > TextBox t = null;
    >
    > try
    > {
    > c = (HttpConnection) Connector.open(url);
    > c.setRequestMethod(HttpConnection.GET);
    > c.setRequestProperty("IF-Modified-Since",
    > "10 Nov 2000 17:29:12 GMT");
    > c.setRequestProperty("User-Agent",
    > "Profile/MIDP-1.0
    > Confirguration/CLDC-1.0");
    > c.setRequestProperty("Content-Language",
    > "en-CA");
    > os = c.openOutputStream();
    >
    > /**
    > String str = "?idnum=182016";
    > byte postmsg[] = str.getBytes();
    > for(int i=0;i<postmsg.length;i++) {
    > os.writeByte(postmsg);
    > }
    > os.flush();
    > */
    >
    > is = c.openDataInputStream();
    > int ch;
    > while ((ch = is.read()) != -1)
    > {
    > b.append((char) ch);
    > }
    > //t = new TextBox("Final Grades", b.toString(), 1024, 0);
    > fForm.append(b.toString());
    > }
    > finally
    > {
    > if (is != null)
    > {
    > is.close();
    > }
    > if (os != null)
    > {
    > os.close();
    > }
    > if (c != null)
    > {
    > c.close();
    > }
    > }
    > //display.setCurrent(t);
    > }
    > }
    >
    > This code has been successfully tested in the emulator.
    >
    > Bill Volk
    > Teknik Digital Arts
    Bill Volk, Jul 2, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Clancy
    Replies:
    0
    Views:
    3,273
    Andrew Clancy
    Jul 18, 2003
  2. Mike Szanto
    Replies:
    0
    Views:
    359
    Mike Szanto
    Aug 28, 2003
  3. Ken Varn
    Replies:
    0
    Views:
    342
    Ken Varn
    Aug 17, 2004
  4. Damien
    Replies:
    1
    Views:
    440
    Damien
    May 20, 2005
  5. Ike
    Replies:
    0
    Views:
    356
Loading...

Share This Page