EOFException in ReadUTF. Please help!!

Hi, I磎 reading a string sent by a servlet to a middlet, using ReadUTF. In a fist moment it worked, by now it throws a java.io.EOFException, I don磘 know why, I think I磛e modified anything.

The midlet receive string code is:

httpConn = (HttpConnection)Connector.open(url);

inStr = httpConn.openInputStream();

DataInputStream dinStr=new DataInputStream(inStr);

DataReceived=dinStr.readUTF(dinStr);

inStr.close();

httpConn.close();

The servlet sends a string using writeUTF:

ServletOutputStream out = response.getOutputStream();

DataOutputStream dout =new DataOutputStream(out);

dout.writeUTF(datatosend);

dout.flush();

dout.close();

Where could be the problem? ReadUTF throws a EOFException when the end of file is reaches? Then why DataReceived doesn磘 contain anything?

I also check if the response code of the servlet is HTTP_OK, that磗 the case.

Sholud I work with the content length or it磗 no necessary to work with readUTF and Strings?

Thanks in advance.

[1131 byte] By [Uinidepua] at [2007-10-3 3:49:05]
# 1
I磛e found the problem. If I remove the line of the servlet code which sends the content length there is no exceptions. response.setContentLength(datatosend.length());But I don磘 know yet if its better to send (correctly) that Content Lentgh or it磗 unnecessary to use with the
Uinidepua at 2007-7-14 21:46:13 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2

> But I don磘 know yet if its better to send

> (correctly) that Content Lentgh or it磗 unnecessary

> to use with the writeUTF.

Did you actually send the correct content length? Please check the writeUTF api docs to find out exactly what it sends. You'll see that your content length was not correct!

deepspacea at 2007-7-14 21:46:13 > top of Java-index,Java Mobility Forums,Java ME Technologies...