Sorry about that. Here is the system description:

Platform: Intel/Mac, Intel Linux, Windows 32bit. All 3 platforms have the
same Tomcat/Java as below.
Tomcat 6.0.26 (no web server installed)
Sun Java:  1.6.0.22

Let me try to describe the code flow a bit more so that it may give a better
understanding of the "connection" between my client and server.

First of all, I did it this way because if I used a different port I could
have opened a socket connection to do my bi-directional communication. Using
port 80 means I have less issues about firewalls. So the flow is as follows:

1) the client worker thread make a servlet request, opens the input stream
to get the servlet response. After the servlet response is received, the
input stream is kept open. From now on the thread periodically checks the
input stream for data and processes it.
2) On the web app side, the servlet gets the request, sends back the
response, but then does not close the output stream. Instead, it does other
work and periodically sends more data (binary data) on the output stream. I
do not do anything special for the "keep-alive".

Notice that so far, this is a one-way (server down to client) flow. What I
want to do is to have two-way communication over a long time. So, the
modified code works like this:

1) the client worker thread makes the servlet request as usual on its output
stream, but then keep that stream open, to later send additional data to the
server. This data is not a servlet request but binary data of my own format.
 The input stream is opened to get the servlet response and to receive
additional other binary data in the future.
2) On the web side, the servlet keeps open the input and output streams,
sends a servlet response and then later sends binary data to the client as
necessary. But now, since it has also kept open the input stream it should
receive the binary data from the client... at least that was my expectation.
Instead, I do not get any data (<stream>.available() always returns 0).

I hope this makes it more clear.

Based on some of the responses, I have an additional question:
1) Should I be doing something explicitly to keep the connection alive or
does the connection close after some inactivity on its own?

Thank you all of looking at my problem.

Sincerely,
- Tosh

Reply via email to