Re: Sockets, writing data and shutdownOutput



HK wrote:
  OutputStream out = socket.getOutputStream();
  out.write(...);
  out.flush();
  socket.shutdownOutput();

Problem: roughly half of the time the server
resets the connection before sending its response?

I use the shutdownOutput to make sure the server
understands that we are done and no more data can
be expected, but it seems that it overinterpretes
it as if my client is not interested in
pending response data?

It is not an over-interpretation. From the API documentation;

... data will be sent followed by TCP's normal connection termination sequence.

I read that as that a FIN is sent, triggering of course the close of the connection on both ends. If you run a network sniffer (highly recommended for all development involving networking, you should see the sequence of FIN > , < ACK, < FIN+ACK, ACK >.
(<, > should indicate the direction of the segments).


Anyone had this problem and can shed some more
light on it?

Don't close the connection until you are done, or until HTTP indicates you can do so. See e.g. section 8.1.2 of the RFC 2616 which you mentioned elsewhere. You might also have to clarify if you are talking to a 1.1 or 1.0 HTTP server, since the default connection keep-alive behavior is different between those two HTTP versions.



  Harald.
------------------------------------------------------------------------
Java Text Crunching: http://www.ebi.ac.uk/Rebholz-srv/whatizit/software

BTW: The correct Usenet signature separator is '-- ' (two hyphens, followed my a mandatory space). Many Usenet clients check for this separator to identify a signature. Your long line of '-' doesn't qualify.


/Thomas

--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
.



Relevant Pages

  • Re: Is yahoo being hijacked?
    ... I get no server response when query ... > Connection: close ...
    (misc.invest.stocks)
  • Re: Is yahoo being hijacked?
    ... I get no server response when query ... > Connection: close ...
    (misc.invest.stocks)
  • Is yahoo being hijacked?
    ... I get no server response when query ... The server returned the following response headers: ... Connection: close ...
    (misc.invest.stocks)
  • Re: Is yahoo being hijacked?
    ... I get no server response when query ... > Connection: close ...
    (misc.invest.stocks)
  • Re: Problems with access to a web page
    ... Server: Apache ... Connection: close ... Look what I get now when I send the exact same request ... and got exactly the same 0 length response ...
    (microsoft.public.windows.inetexplorer.ie6.browser)