Forums Register Login

can i do that

+Pie Number of slices to send: Send
can i layer the stream of a socket in a certain type of stream and when i finished with the layer one i continue using the low level one.
to describe what i mean:
InputStream ins=new InputStream(
socket.getInputStream());
DataInputStream dis=new DataInputStream(ins);
int i=dis.readInt();
//i finished with the data input seram
while(someCondition){
int x=ins.read();
}
and if that is possible, can i layer the stream with DataInputStream ,then when i finished working with that layer, i layer the input stream with another stream like ByteArrayInputStream.
+Pie Number of slices to send: Send
Hi,
It does not matter that how many types of streams you use but you are apparently using the same stream. SO you can read only once. Once you read a data in the stream it is removed from the stream.
Also, if you close any one stream, you cannot read data in any of the other streams.
Not very sure, that some streams support retaining the data in the stream even after it has been read - need to verify this.
+Pie Number of slices to send: Send
you misunderstood me, actually what i intened is
determining first the type of the request and then reading the additional information needed according to that type of request, i want to use
DataInputStream at this stage (i will not need the bytes that is read anymore) ,then i layer the input stream of the socket with another stream to
read the remaining bytes which is the actual data.
what confuse me really that the supervisor of my graduation project ( File sharing with chat ) tells me that i can use one ServerSocket at the client side ( actuallly his time is little to argue with me more time ).
+Pie Number of slices to send: Send
Hi,
You can layer the stream(Socket) as many times as you please, After reading some data you can layer it into an ObjectInputStream stream and read an object... what ever way you please. But the rule is that you are seeing the stream as one.
The main difference between the ServerSocket and the Socket is that the former can listen for someone to connect, then it is a normal socket.
I guess you want to read the request from a chat client and send the file in the same stream. Is my guess valid enough?
This tiny ad will self destruct in five seconds.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1007 times.
Similar Threads
Chained Streams
Valid???
input/output
getContentLength
skip() method of InputStream???
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 03:38:03.