Problem servlet/midlet communication using HTTP in the device
Hi, I磎 trying to do a midlet communicating with a simple servlet, sending a string and then receiving the servlet response (as a string too), but when I try the application in a real device,a siemens cf75, it doen磘 work. After accepting the http connection, the application blocks in the waitscreen, showing the "wait for the http connection" message. I磛e tryed in the specific cf 75 emulator and works properly.
The method which opens the Http connection is:
private HttpConnection sendData(HttpConnection httpConn,OutputStream ouStr)throws IOException{
//we set the Http Connection
String url ="http://200.17.77.2:8082/Proyecto2BlueP/ServletProyecto2_1BP";
httpConn = (HttpConnection)Connector.open(url);
httpConn.setRequestMethod( HttpConnection.POST );
httpConn.setRequestProperty("User-Agent",
"Profile/MIDP-1.0 Configuration/CLDC-1.0" );
httpConn.setRequestProperty("Content-Language","en-US" );
httpConn.setRequestProperty("Accept","application/octet-stream" );
httpConn.setRequestProperty("Connection","close");
httpConn.setRequestProperty("Content-Length",Integer.toString((DataEncoded.toString()).length()));
httpConn.setRequestProperty("Content-Type","application/octet-stream" );
ouStr = httpConn.openOutputStream();
DataOutputStream douStr =new DataOutputStream(ouStr);
//Data send (we transform the StringBuffer into a String)
douStr.writeUTF(DataEncoded.toString());
douStr.flush();
//We close the connection
ouStr.close();
return httpConn;
}
And the method which receives the data:
privatevoid connect(){
HttpConnection httpConn =null;
OutputStream ouStr=null;
boolean ret =false;
try{
//the code we have just seen:
httpConn=sendData(httpConn,ouStr);
//Now we reveive the data send by the servlet
InputStream inStr =null;
inStr = httpConn.openInputStream();
System.out.println("Hemos abierto el inputStream");
int contentLength = (int)httpConn.getLength();
int rc = httpConn.getResponseCode();
if( rc == HttpConnection.HTTP_OK ){
DataInputStream dinStr=new DataInputStream(inStr);
System.out.println("Nuevo Data Input Stream");
DataReceived=dinStr.readUTF(dinStr);
inStr.close();
httpConn.close();
}
else{
}
}
catch( IOException e ){
System.out.println("Error en la conexion!!!!");
System.out.println("IOException: "+e);
}
}
I磎 using netbeans 5.0. I dont know if the problem is because using openInputStream, or with the threads that are not well implented (in theory it磗 very intuitive to do int with the mobility pack and adding a simpleCancellableTask), or perhaps because the waitScreens. What can be the possible reasons of working in the emulator and not in the real device (it implements MIPD 2.0 and CLDC/1.1)?
Thanks a lot in advance!!!

