Problems transferring multiple files
I'm trying to write a program to transfer multiple files from a client to a server, but I'm having trouble getting the server to distinguish between them.
I have tried both buffered streams, and straight input/output streams, and in both cases, the server doesn't seem to get any EOF, and keeps reading all data it reads into the first file. I can't figure out why EOF is never read (ie: ((read = bis.read(buffer)) != -1) never evaluates to -1). Can anybody see why that might be?
Client:
buffer =newbyte[16384];
out= serverSocket.getOutputStream();
bos=new BufferedOutputStream(out);
objOut =new ObjectOutputStream(out);
objOut.writeInt(file.length);// # of files to transfer
for (int i=0; i<file.length; i++){
try{
fileIn =new FileInputStream(file[i].getAbsolutePath());
objOut.writeLong(file[i].length());// file length (for dirty CRC check)
objOut.writeObject(file[i].getName());// file name
objOut.flush();// because otherwise the server hangs waiting
while ((read = fileIn.read(buffer)) > 0){
bos.write(buffer, 0, read);
bos.flush();
}
}
catch (Exception e){}
}
Server:
in = socket.getInputStream();
objIn =new ObjectInputStream(in);
bis =new BufferedInputStream(in);
fileCnt = objIn.readInt();// # of files to be transferred
for (int i=0; i<fileCnt; i++){
totalLen = objIn.readLong();// file length
try{ fileName = (String)objIn.readObject();}// file name
catch (Exception e){}
try{ toFile =new FileOutputStream(new File(fileName));}
catch (FileNotFoundException ex){}
while ((read = bis.read(buffer)) != -1){
toFile.write(buffer, 0, read);
}
}
>

