Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Strange HTTP Socket Problem...

Reply
Thread Tools

Strange HTTP Socket Problem...

 
 
Craig Lindley
Guest
Posts: n/a
 
      07-09-2004
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.


 
Reply With Quote
 
 
 
 
Chris Uppal
Guest
Posts: n/a
 
      07-09-2004
Craig Lindley wrote:

> 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


 
Reply With Quote
 
 
 
 
Craig Lindley
Guest
Posts: n/a
 
      07-09-2004
"Chris Uppal" <> wrote in message
news:BeOdnWVaAv6j_XPdRVn-...
> Craig Lindley wrote:
>
> > 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

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.


--
Craig.


 
Reply With Quote
 
Silvio Bierman
Guest
Posts: n/a
 
      07-09-2004

"Craig Lindley" <> wrote in message
news:...
> "Chris Uppal" <> wrote in message
> news:BeOdnWVaAv6j_XPdRVn-...
> > Craig Lindley wrote:
> >
> > > 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
>
> 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.
>
>
> --
> Craig.
>
>



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


 
Reply With Quote
 
Craig Lindley
Guest
Posts: n/a
 
      07-09-2004
"Silvio Bierman" <> wrote in message
news:40ee69d5$0$566$...
>
> "Craig Lindley" <> wrote in message
> news:...
> > "Chris Uppal" <> wrote in message
> > news:BeOdnWVaAv6j_XPdRVn-...
> > > Craig Lindley wrote:
> > >
> > > > 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
> >
> > 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.
> >
> >
> > --
> > Craig.
> >
> >

>
>
> 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.


--
Craig.


 
Reply With Quote
 
Kevin McMurtrie
Guest
Posts: n/a
 
      07-10-2004
In article <>,
"Craig Lindley" <> wrote:

> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 1 02-03-2009 06:20 AM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 0 02-01-2009 12:45 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 0 02-01-2009 07:37 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57