Re: Sockets, writing data and shutdownOutput
- From: Thomas Weidenfeller <nobody@xxxxxxxxxxxxxxxx>
- Date: Wed, 03 Aug 2005 10:57:47 +0200
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/ .
- Follow-Ups:
- References:
- Prev by Date: Re: JAWS and Netscape/Firefox
- Next by Date: Re: How to check if byte array is compressed or not?
- Previous by thread: Re: Sockets, writing data and shutdownOutput
- Next by thread: Re: Sockets, writing data and shutdownOutput
- Index(es):
Relevant Pages
|