why the data length is different between the client and server through socket??
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   wind_jie
Posted On:   Wednesday, August 28, 2002 08:32 PM

my system is:the client send some data byte[] to the server,the server receive it,using socket,outputstream,inputstream.now the problem is:the sender's data length is different with the receiver's length!
The Client:
Os=socket.getOutputStream();
Os.write((byte[])buf.getData());
Os.flush();


The Server:
int byteCount=is.available();
bytes=new byte[byteCount];
is.read(bytes);

the bytes' length in server is different with that in client

why??
and help are appreciated

Re: why the data length is different between the client and server through socket??

Posted By:   Axel_Richter  
Posted On:   Thursday, August 29, 2002 01:15 AM

That is according to my opinion no Socket problem. You assume that is.available() return the size of the entire byte array. Whereupon I did not rely.



Use a BufferedInputStream is and do something like this:

Vector v = new Vector();
while((i = is.read()) != -1) {
b = new Byte((byte)i); //or other type
v.add(b);
}
out.close();
About | Sitemap | Contact