socket DataOutput problems

Hi,

For my client/server program i am having problems with my client recieving the correct amount of data. when i step through the client it does not always receive all the bytes for the first stream. Edit: My client program will just freeze after during the 2nd transfer or the 6th. its at random times. the file does transfer but information on the clients screen does not update.

this is the code for my server

Java Code:

FileInputStream fileInput = new FileInputStream(file); //create fileInputStream of file
DataOutputStream stream = new DataOutputStream(socket.getOutputStream()); //creat DataOutputStream of the socket
byte[] bb = new byte[10000]; //create a byte that stores 10000 bytes
start = System.currentTimeMillis(); //get the current time in milliseconds
while (true) { //loop untill file is sent
int result = fileInput.read(bb); //read 10000 bytes of the file into result
if (result == -1) { //check if end of file has been read
break; //exit while loop
}
stream.write(bb, 0, result); //send 10000 bytes of file to the client
stream.flush();
}

client

Java Code:

DataInputStream dataInput = new DataInputStream(socket.getInputStream()); //create a new instance of a DataInputStream in order to get data from server
FileOutputStream fileOutput = new FileOutputStream(path.trim() + "\\" + newFileName.trim()); //create new instance of FileOutputStream to write the file to the clients computer
byte[] bb = new byte[10000]; //create a new instance of a byte
while (true) {
int result = dataInput.read(bb); //read 10000 bytes and place bytes in variable called result
fileOutput.write(bb, 0, result); //write a file on input
if (fileSize == result) { //check if result is equal to the filesize
break; //break while loop
}
fileSize -= result; //subtract result from fileSize
}

edit: also if i step through the server the client and the serve work just fine. I can't figure out why my client will occasionally just freeze on me.