• Post Reply Bookmark Topic Watch Topic
  • New Topic

can i do that

 
mohamed hamdy
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vijayakumar Arya
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
mohamed hamdy
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ).
 
Vijayakumar Arya
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!