Hi to all for serveral days i'm trying to solve this problem without success. The problem occurs only on SERIE60_FP2. When i call the method
---->int rc=c.getResponseCode();
the device, also the emulator, hangs.
if i delete the code above the device,also the emulator, hangs on
---->is = c.openInputStream();
so every read call hangs-up.
The same code in other devices and emulators rather than SERIE60_FP2 (I.E. NokiaN70) works great. I've tested on the following real devices:
1. NokiaN70 OK
2. Nokia6630 KO V.5.03.08
and on a lot of emulator (excluding the SERIE60_FP2 emulator all the others works great)
Here is my source code:
byte[] GetHttpData(String url) throws IOException{
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
InputStream is = null;
HttpConnection c = null;
byte strData[]=null;
long len = 0 ;
int ch = 0;
try {
c = (HttpConnection)Connector.open(url);
c.setRequestMethod("GET");
int rc=c.getResponseCode();
is = c.openInputStream();
len =c.getLength();
if (lunghezzaTotale==-1) {lunghezzaTotale=len;}
if( len != -1) {
// Read exactly Content-Length bytes
for(int i =0 ; i < len ; i++ )
if((ch = is.read()) != -1) {
byteStream.write(ch);
}
} else {
//Read until the connection is closed.
while ((ch = is.read()) != -1) {
len = is.available() ;
byteStream.write(ch);
}
}
strData=byteStream.toByteArray();
}catch (IOException ioex){
mc.messaggio(ioex.toString(),this.mm,0);
} finally {
try {
if (c != null) c.close();
if (is!= null) is.close();
}catch (IOException ioex){
mc.messaggio(ioex.toString(),this.mm,0);
}
return strData;
}
}
The code is invoked by a different thread and i've also tried to put a Thread.sleep(1000) method before communication begin as reported in others thread in forum.
ANY IDEA????
Thanks a lot.

Reply With Quote


