Hello, I try several weeks solve my issue. I try build any example for error testing:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package hello;
import java.io.InputStream;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.*;
/**
* @author Licman
*/
public class TestConn extends MIDlet
implements CommandListener {
static Display d;
public Form form;
private Command cmdExit;
private Command cmdConnect;
private static String URL = "http://flexijobsin.lsw.cz/recfile.aspx";
public void startApp() {
d = Display.getDisplay(this);
form = new Form("Test HTTP connection");
cmdExit = new Command("Exit", Command.CANCEL, 2);
cmdConnect = new Command("Connect", Command.OK, 2);
form.addCommand(cmdExit);
form.addCommand(cmdConnect);
form.setCommandListener(this);
d.setCurrent(form);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
private void Exit()
{
destroyApp(true);
notifyDestroyed();
}
private void SendData() {
String s = "ABCDEFGHIJKLMNOPXXXXXXXXXXXXX";
byte outputBytes[] = s.getBytes();
String strRes = SendBuffer(outputBytes);
form.append(strRes);
}
public void commandAction(Command c, Displayable d) {
if(c == cmdExit) {
Exit();
}
if(c == cmdConnect) {
SendData();
}
}
public String SendBuffer(byte FldBytes[]){
HttpConnection conn = null;
OutputStream os = null;
InputStream is = null;
int intBytesShots = 0;
StringBuffer b = new StringBuffer();
StringBuffer sbErr = new StringBuffer();
boolean blnIsInProgress = false;
if (blnIsInProgress == false) {
blnIsInProgress = true;
try{
if (FldBytes != null) {
intBytesShots = FldBytes.length;
form.append("Before open HTTP \n");
try {
conn = (HttpConnection)Connector.open(URL);
conn.setRequestMethod(HttpConnection.POST);
} catch (Exception e) {
sbErr.append("1: ").append(e.toString());
}
form.append("Before openOutputStream \n");
try {
os = conn.openOutputStream();
} catch (Exception e) {
sbErr.append("2: ").append(e.toString()).append("\n");
}
// SEND buffers in loop
int index = 0;
int size = 512;
form.append("Before send stream in loop \n");
try {
do{
if((index+size) > intBytesShots){
size = intBytesShots - index;
if (size == 0) {
break;
}
}
os.write(FldBytes, index, size);
index+=size;
}while(index < intBytesShots);
} catch (Exception e) {
sbErr.append("3: ").append(e.toString()).append("\n");
}
form.append("Will flush and close \n");
os.flush();
os.close();
form.append("Before openInputStream \n");
is = conn.openInputStream();
long len = 0;
int ch = 0;
len = conn.getLength();
if (len != -1) {
for (int i = 0; i < len; i++)
if ((ch = is.read()) != -1)
b.append((char) ch);
} else {
// Read til the connection is closed.
// (Typical HTTP/1.0 script generated output)
while ((ch = is.read()) != -1) {
// is.available() );
len = is.available();
// For HTTP 1.1 servers, chunked reads.
b.append((char) ch);
}
}
}
}catch(Exception e){
sbErr.append("4: ").append(e.toString()).append("\n");
}finally{
try{
os.close();
}catch(Exception e){}
try{
is.close();
}catch(Exception e){}
try{
conn.close();
}
catch(Exception e){}
}
os = null;
is = null;
conn = null;
}
if (sbErr.length() >0) {
b = null;
b = new StringBuffer();
b.append(sbErr.toString());
}
blnIsInProgress = false;
return b.toString();
}
}
My Issue is:
On first calling of "SendBuffer" function it works fine. Anytime in second calling too. Test application hangup in next calling. Application stop on command "os.flush();" Response is not after several minutes. Anytime it write "IOException -33" but anytime it do nothing. ONly applicaciton from.
I use for testing mobile device Nokia C5-00 with OS symbian. For developing I use NetBeans7.
Can you get me a tip or help please? It's very imporetant form me and I lost lot of time with finding of any solution. But I don't have a succes.
Thank you in advice for all tips.

Reply With Quote



