473,569 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tomcat doesn't send all data while Jetty does

I am using the following code in a servlet to send data back to a J2ME
application:
Jul 17 '05 #1
4 5343
On Fri, 11 Jul 2003 09:22:53 -0400, BigAl <a.***********@ ieee.org>
wrote or quoted :
Simply put, what is wrong ? Is there a setting in Tomcat that I should
look at ?


If you are reading at the raw socket level, remember that the data
come in chunks, not all in one piece.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Jul 17 '05 #2
redir to cljs

"BigAl" <a.***********@ ieee.org> schrieb im Newsbeitrag
news:3F******** ******@ieee.org ...
I am using the following code in a servlet to send data back to a J2ME
application:
Which version of Tomcat do you use? Is it current?
.
.
data = myResp.serializ e();
response.setSta tus(response.SC _OK);
response.setCon tentLength(data .length);
response.setCon tentType("appli cation/octet-stream");
OutputStream os = response.getOut putStream();
os.write(data);
os.flush();
os.close();
First, flush is superfluous before a close, as defined by OutputStream.

Second, I'd prefer to use response.flushB uffer() instead of os.flush() and
leave out os.close(). Try this:

data = myResp.serializ e();
response.setSta tus(response.SC _OK);
response.setCon tentLength(data .length);
response.setCon tentType("appli cation/octet-stream");
OutputStream os = response.getOut putStream();
os.write(data);
response.flushB uffer();

Regards

robert
.
.
and the following input code on the J2ME side (simplified a bit):
.
.
int len = (int)conn.getLe ngth();
in = conn.openInputS tream();
_data = new byte[len];
while (total < len) {
total += in.read(_data, total, len - total);
}
.
.
Using Jetty as the servlet container, I am able to SEND and RECEIVE data
without any problem. Using Tomcat, I usually get a -1 on the CLIENT side
when trying to read the data. The CLIENT gets the length from the
content header but there doesn't seem to be any data.

Simply put, what is wrong ? Is there a setting in Tomcat that I should
look at ? Why would Jetty work with this code and not Tomcat ? This
seems like simple standard stuff.

Thanks

=Alan=


Jul 17 '05 #3
I'm using Tomcat Version 4.1.24 - fairly recent. Jetty is Version 4.2.9
- also fairly recent.

I tried the response.flushB uffer() but I still have the same issue
(detailed below). Here is some more information:

If I run my J2ME app within the Wireless Toolkit, Tomcat and Jetty both
work fine. When I download the app to a phone (in this case a Motorola
T720), the app is able to receive messages from the Jetty servlet
container but not from Tomcat.

Here is a snippet of the phone code where we read from the input stream:

byte[] _data;
int len = (int)conn.getLe ngth();
in = conn.openInputS tream();

if (len != -1) {
_data = new byte[len];
while (total < len) {
total += in.read(_data, total, len - total);
}
} else {
ByteArrayOutput Stream tmp = new ByteArrayOutput Stream();
int ch;
while ((ch = in.read()) != -1) {
tmp.write(ch);
total++;
}
_data = tmp.toByteArray ();
}
Thanks

=Alan=

Robert Klemme wrote:
redir to cljs

"BigAl" <a.***********@ ieee.org> schrieb im Newsbeitrag
news:3F******** ******@ieee.org ...
I am using the following code in a servlet to send data back to a J2ME
application :

Which version of Tomcat do you use? Is it current?

.
.
data = myResp.serializ e();
response.setSta tus(response.SC _OK);
response.setCon tentLength(data .length);
response.setCon tentType("appli cation/octet-stream");
OutputStream os = response.getOut putStream();
os.write(data);
os.flush();
os.close();

First, flush is superfluous before a close, as defined by OutputStream.

Second, I'd prefer to use response.flushB uffer() instead of os.flush() and
leave out os.close(). Try this:

data = myResp.serializ e();
response.setSta tus(response.SC _OK);
response.setCon tentLength(data .length);
response.setCon tentType("appli cation/octet-stream");
OutputStream os = response.getOut putStream();
os.write(data);
response.flushB uffer();

Regards

robert

.
.
and the following input code on the J2ME side (simplified a bit):
.
.
int len = (int)conn.getLe ngth();
in = conn.openInputS tream();
_data = new byte[len];
while (total < len) {
total += in.read(_data, total, len - total);
}
.
.
Using Jetty as the servlet container, I am able to SEND and RECEIVE data
without any problem. Using Tomcat, I usually get a -1 on the CLIENT side
when trying to read the data. The CLIENT gets the length from the
content header but there doesn't seem to be any data.

Simply put, what is wrong ? Is there a setting in Tomcat that I should
look at ? Why would Jetty work with this code and not Tomcat ? This
seems like simple standard stuff.

Thanks

=Alan=


Jul 17 '05 #4
"BigAl" == BigAl <a.***********@ ieee.org> writes:

BigAl> phone (in this case a Motorola T720), the app is able to
BigAl> receive messages from the Jetty servlet container but not
BigAl> from Tomcat.
BigAl> Here is a snippet of the phone code where we read from the
BigAl> input stream:

byte[] _data;
int len = (int)conn.getLe ngth();
in = conn.openInputS tream();

I've never done J2ME, but I am guessing that the conn.getLength( )
method is not returning the number of bytes in the response, it is
returning the number of bytes available to read from the connection
(i.e. you are hitting a network timing issue).

if (len != -1) {
_data = new byte[len];
while (total < len) {
total += in.read(_data, total, len - total);
}
} else {
ByteArrayOutput Stream tmp = new ByteArrayOutput Stream();
int ch;
while ((ch = in.read()) != -1) {
tmp.write(ch);
total++;
}
_data = tmp.toByteArray ();
}

This remaining code makes me even more suspicious. When do you get
-1 for len? Why? Does you code work if you simply use only the 'else'
clause? Perhaps I'm wrong since I know nothing about J2ME, but the
mistake I am describing is a very common one when people write code to
read off TCP connections.

Cheers!
Shyamal
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
4019
by: nmac | last post by:
Hi all, hopefully someone can offer some sagely advice regarding Production use of Jakarta's Tomcat. First, some brief background. My company have a servlet application that connects to a MySQL database. The servlet is deployed on two seperate win2k servers (Access to the tomcat servers is via DNS round robin load balancing). The database...
6
12124
by: DaiIchi | last post by:
I'm using Tomcat in standalone mode. When a URL without a filename is entered into the browser (ie. "http://myhost.mydomain.com"), and the default path does NOT have an index.html, but rather an index.jsp file, Tomcat response with an "HTTP/1.1 302 Moved Temporarily" and a "Location: http://myhost.mydomain.com/index.jsp" ... I was wondering...
1
7109
by: jajoo | last post by:
Hi everyone, I am trying to send files with multipart/form-date. Everything is ok with the send. But when I am receiving the files I should specify a directory where the files to be saved. The problem is that Tomcat saves the files into %CATALINA_HOME%/bin directory. I am wondering why? Why not into my application directory? The application...
0
1639
by: Abel Suarez | last post by:
Hello everybody!! We have a web application using JRun 2.3.2 and all were correct, but we have been obliged to migrate to Tomcat, because JRun 2.3.2 is not going to be sold any more (it is a shame, because Macromedia doesn't sell this license but if you buy JRun 4.0 it doesn't cover 2.3.2 version, so it is a product that can't be bought but...
1
2157
by: Dmitriy A | last post by:
Hi, I have an problem that I've been struggling with for a week now and simply can not resolve. I have an MFC C++ application that sends a request to a servlet which sends back data continuously - the doGet method does not return until the client quits. In a different thread of the same MFC app, I start periodically sending requests to a...
2
3947
by: Jakub Pawlowski | last post by:
I'm using Jetty(version 4.2.19). In my servlet I put following lines: System.out.println("before: " + resp.containsHeader("aaa")); resp.setHeader( "aaa", "test" ); System.out.println("after: " + resp.containsHeader("aaa"));
0
2003
by: witichis | last post by:
Hi, using jetty 4.2.9 on redhat with sun jdk 1.4.2_01-b06 When using virtual hosts the java process dies after a few minutes while the CPU load goes slowly from 100% to zero (e-function?) on that process. Without virtual hosts jetty usually runs for months (no restarts necessary) on this setup. There is nothing unusual in the logs or...
0
1439
by: Richard | last post by:
Hello! I have 2 questions regarding Xindice (http://xml.apache.org/xindice/): 1) Does anyone know how to set the encoding??? Normaly im using encoding="iso-8859-1" in my xml-files, this makes it possible to use swedish characters. The problem is that every time im pulling someting out from Xindice the encoding is lost, and all my...
0
2140
by: Rajendra Pote | last post by:
Hi all, I have installed apache and tomcat on linux server. Both are communicating through jk module. But some times tomcat do not respond. When I listed all process by using ps -ax on linux prompt, it shows me tomcat PID. Can any one suggest me solution. I am enclosing jk.logs Thanks and Regards, Rajendra Pote...
0
7697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7968
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.