Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Java - java.net.Socket.close() and getInputStream

 
Thread Tools Search this Thread
Old 03-10-2005, 04:19 PM   #1
Default java.net.Socket.close() and getInputStream


Hi,

after obtaining an InputStream from a Socket,
do I have to close it seperately or does it
suffice to close the Socket itself?

Thanks,
Harald.



HK
  Reply With Quote
Old 03-10-2005, 06:41 PM   #2
Gordon Beaton
 
Posts: n/a
Default Re: java.net.Socket.close() and getInputStream
On 10 Mar 2005 08:19:01 -0800, HK wrote:
> after obtaining an InputStream from a Socket, do I have to close it
> seperately or does it suffice to close the Socket itself?


You should close the InputStream. It will close the Socket for you.

If you wrap the InputStream in another stream type, close that
instead. In other words, always close the *outermost* stream.

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e


Gordon Beaton
  Reply With Quote
Old 03-11-2005, 09:04 AM   #3
Martin A
 
Posts: n/a
Default Re: java.net.Socket.close() and getInputStream
Gordon Beaton wrote:

>On 10 Mar 2005 08:19:01 -0800, HK wrote:
>
>
>>after obtaining an InputStream from a Socket, do I have to close it
>>seperately or does it suffice to close the Socket itself?
>>
>>

>
>You should close the InputStream. It will close the Socket for you.
>
>
>

Is it possible to close a Socket's InputStream but not close the Socket,
and then use its OutputStream for example?



Martin A
  Reply With Quote
Old 03-11-2005, 11:29 AM   #4
Gordon Beaton
 
Posts: n/a
Default Re: java.net.Socket.close() and getInputStream
On Fri, 11 Mar 2005 10:04:46 +0100, Martin A wrote:
> Is it possible to close a Socket's InputStream but not close the
> Socket, and then use its OutputStream for example?


Socket.shutdownInput() in that case.

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e


Gordon Beaton
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

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