Strange HTTP Socket Problem...

C

Craig Lindley

Hi,

I've written a small HTTP server that also handles servlets. It works
perfectly fine for files and almost perfectly fine for servlets. The
strange problem that occurs with servlets is as follows:

The servlet runs fine, fills the PrintWriter (backed onto a
ByteArrayOutputStream) fine, I output the HTTP header to the socket
(Internet Explorer) flush it, then write the body of the servlet. This
seems to work fine for smaller servlets, but as soon as the servlet outputs
a larger amount of data it gives a 90% "page cannot be displayed" message.
The REALLY strange thing is, if I wait 50ms or so after flushing the streams
and before I close the socket, all works fine. Although on one machine the
50ms delay had to be cranked upto 1000ms before it didn't "page cannot be
displayed".

ANY and all ideas welcome!!!

Thanks,
Craig.
 
C

Chris Uppal

Craig said:
as soon as the servlet
outputs a larger amount of data it gives a 90% "page cannot be displayed"
message. The REALLY strange thing is, if I wait 50ms or so after flushing
the streams and before I close the socket, all works fine.

Are you closing the socket itself, or the OutputStream that is connected to it
?

-- chris
 
C

Craig Lindley

Chris Uppal said:
Are you closing the socket itself, or the OutputStream that is connected
to it

I've flushed the stream, closed the stream and then closed the socket. I've
tried various combinations of the above, even tried NOT closing anything and
seeing if IE will do that for me. I've also tried checking that there's no
more data on the inputstream.
 
S

Silvio Bierman

Craig Lindley said:
to it

I've flushed the stream, closed the stream and then closed the socket. I've
tried various combinations of the above, even tried NOT closing anything and
seeing if IE will do that for me. I've also tried checking that there's no
more data on the inputstream.


Do you generate a content length header with the correct bytecount? Do you
handle the connection keep alive header?

A HTTP server has quite some nifty demands to fullfill. Connection and
content length handling are examples of this.

Silvio Bierman
 
C

Craig Lindley

Silvio Bierman said:
Do you generate a content length header with the correct bytecount? Do you
handle the connection keep alive header?

I do indeed. I don't handle keep alive, I return connection close.
A HTTP server has quite some nifty demands to fullfill. Connection and
content length handling are examples of this.

Most of them are straightforward enough I've found.
 
K

Kevin McMurtrie

Craig Lindley said:
Hi,

I've written a small HTTP server that also handles servlets. It works
perfectly fine for files and almost perfectly fine for servlets. The
strange problem that occurs with servlets is as follows:

The servlet runs fine, fills the PrintWriter (backed onto a
ByteArrayOutputStream) fine, I output the HTTP header to the socket
(Internet Explorer) flush it, then write the body of the servlet. This
seems to work fine for smaller servlets, but as soon as the servlet outputs
a larger amount of data it gives a 90% "page cannot be displayed" message.
The REALLY strange thing is, if I wait 50ms or so after flushing the streams
and before I close the socket, all works fine. Although on one machine the
50ms delay had to be cranked upto 1000ms before it didn't "page cannot be
displayed".

ANY and all ideas welcome!!!

Thanks,
Craig.

Got code? Here are some random thoguhts -

Did you mess with Socket.setSoLinger(boolean on, int linger)? When you
close your socket, it waits the specified amount of time for the client
to finish. The socket is reset (aborted) if time runs out. Fussing
with the OS defaults can cause the same problem.

Make sure you're closing everything in the opposite order you opened it.
Closing the socket before closing the output stream can abort some data.
Character to byte converters properly is important because they lag by a
few bytes. Check that your streams pass along close() properly.

Don't share buffers between threads while they're in use.

Socket.close() is asynchronous. The JVM shouldn't quit right after
closing a socket or server socket. Don't try to re-open a specific port
unless you've manually specified the SO_LINGER value and have waited
that long.

If you're using transfer encoding or compression, double check that it
is correct. They're very tricky to get right.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top