Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > J2ME Network Problems, Network Lockup after 13+ GETs

Reply
Thread Tools

J2ME Network Problems, Network Lockup after 13+ GETs

 
 
Bill Volk
Guest
Posts: n/a
 
      07-01-2003
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[i]);
}
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
 
Reply With Quote
 
 
 
 
Bill Volk
Guest
Posts: n/a
 
      07-02-2003
Note: Have verified this with a commerical application ... WebViewer.

Bill


http://www.velocityreviews.com/forums/(E-Mail Removed) (Bill Volk) wrote in message news:<(E-Mail Removed). com>...
> 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[i]);
> }
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Return of gets gets John Joyce Ruby 0 04-23-2007 01:38 PM
gets gets John Joyce Ruby 2 03-26-2007 04:00 PM
XMLHttpRequest gets data to display in element but data gets appended not replaces previous! libsfan01 Javascript 5 12-20-2006 06:25 AM
Not only the selected HREF gets surrounded, but the whole row gets surrounded Stefan Mueller HTML 5 07-10-2006 11:53 AM
Can i using j2me program to download and run other j2me programs in emulator? robin Java 0 07-20-2003 12:59 AM



Advertisments