?
=?iso-8859-2?B?QWRhtg==?=
Hi,
I was wondering what does exactly methods getInputStream and
getOutputStream methods in Socket class do?
I always imagined that there is some fixed stream inside Socket and all
we get is a reference to it. But then I thought what if I get the
stream and create instance of some not abstract Stream, close it, and
then try to open it again.
eg.
Socket s = new Socket(...);
ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
Object o = in.readObject();
[...]
in.close();
BufferedReader r = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
String str = r.readLine();
[...]
r.close();
would it work?? or would it throw exception because it has already been
closed?
The other thing that crossed my mind was what if I'd try to open many
differed streams from one socket at once? I seriously doubt it would
work but, of course, I might be wrong .
I was wondering what does exactly methods getInputStream and
getOutputStream methods in Socket class do?
I always imagined that there is some fixed stream inside Socket and all
we get is a reference to it. But then I thought what if I get the
stream and create instance of some not abstract Stream, close it, and
then try to open it again.
eg.
Socket s = new Socket(...);
ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
Object o = in.readObject();
[...]
in.close();
BufferedReader r = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
String str = r.readLine();
[...]
r.close();
would it work?? or would it throw exception because it has already been
closed?
The other thing that crossed my mind was what if I'd try to open many
differed streams from one socket at once? I seriously doubt it would
work but, of course, I might be wrong .