Skip to main content

sending a photo from midlet to servlet

2 replies [Last post]
oldshoe
Offline
Joined: 2008-08-27
Points: 0

Hello!
My Code worked sometimes ago. But now I needed to implement it again and it doesn't work anymore. Please help me I don't understand the problem.

i get a long error message on server...
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)..................

the interesting part of servlet code:

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

InputStream in = request.getInputStream();
BufferedReader r = new BufferedReader(new InputStreamReader(in));
StringBuffer buf = new StringBuffer();
String line;
while ((line = r.readLine()) != null) {
buf.append(line);
}
String s = buf.toString();

Here the server stands still in the while statement.

MIDlet code:

public void send(){
{
HttpConnection connection = null;
OutputStream os = null;

try
{
String stringImage = Base64.encode(aufnahmeData);
connection = (HttpConnection) Connector.open(url);
os = connection.openOutputStream();
os.write(stringImage.getBytes(),0,stringImage.getBytes().length);

os.flush();
os.close();
connection.close();
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sfitzjava
Offline
Joined: 2003-06-15
Points: 0

The operator's gateway may be causing this issue.
You data stream will be very large because you are base64 encoding.
(BTW: Why are you Base64 encoding and not just sending the binary?)

You might try having the server write a 2k buffer of data instead of trying
to force the entire buffer down the pipe. Doing a long write of data can
sometimes cause an issue, such as a socket timeout, if the gateway is
not setup to handle that type of thing. (sometimes done as a defense against
users getting hit with a large data overage bill.)

-Shawn

oldshoe
Offline
Joined: 2008-08-27
Points: 0

OH MAN...THANKS!
"OPERATORS GATEWAY" was the word! I closed my kaspersky firewall and everything works fine! Hours of work solved in seconds.

Thank you!

PS: I used the base64 channel coding algorithm because sometimes I got mistakes in the pictures after receiving.